Custom kendonumeric max value more than 16 digits - c#

I use NumericTextBoxFor to show amount in my application.
I need to show 20 digits.
Can I accomplish it using NumericTextBoxFor?
I've been trying "max", but kendo just give 16 digits.
#(Html.Kendo().NumericTextBoxFor(model => model.To)
.Max(999999999999999999) //just 16 digits
.Spinners(false)
)
I tried to set 88888888888888888888 but it shows me 88888888888888885248.

Since the actual logic takes place client side, you are most likely getting funny results because the maximum value you can store in a JavaScript Number is 9,007,199,254,740,992. After that, it is representing it as an exponent and losing precision.
I tried doing this max test on the Kendo web site, I did see the value you were talking about, but when you click in the input box it turns to 88888888888888890000, which makes sense if it is turning it into an exponent.
See this and this for more information.
Also an alternative to max value, you could also try a Kendo mask docs here

Related

Calculating percentage value varies between javascript and c#

I am trying to calculate the percentage value and I need it to be similar between the javascript and c#, but it differs.
For ex.: 8.70 percentage of 85 = 7.394999999999999 in javascript, but in c# its 7.395.
How can I have the javascript to have the same output as c#. Please suggest.
Edit:
I am having difficulty in rounding off the value when calculating 8.70% percentage of 85 and 9.25.
The result for 8.70% of 85 should be 7.40, but javascript gives 7.39.
The result for 8.70% of 9.25 should be 0.80 which is fine.
Below is the code I have used in javascript:
(85*8.70/100).toFixed(2)
(9.25*8.70/100).toFixed(2)
Any inputs please?
Just use the toFixed(n) method which rounds the number to n digits after the decimal point:
7.394999999999999.toFixed(3);
For a complete list methods that are available on numbers, check the MDN documentation
In C#, 85d*8.7d/100d gives 7.3949999999999987. On the other hand, 85d/100d*8.7d gives 7.395. If you use the exact same precision data types and arithmetics, the results should be the same, but it's hard to get it right, especially in a multi-platform way. So you should use rounding, just like you should almost always use rounding when you work with floating-point numbers.

How does String.Format work in this situation?

I have a website where you can buy stuff, and we want to format the orderID that goes to our portal in certain way. I am using the string.format method to format it like this:
Portal.OrderID = string.Format( "{0}{1:0000000}-{2:000}",
"Z",
this.Order.OrderID,
"000");
So we want it to look like this basically Z0545698-001. My question is, if I am using string.format will it blow up if this.Order.OrderID is greater than 7 characters?
If so, how can I keep the same formatting (i.e. Z 1234567 - 000) but have the first set of numbers (the 1-7) be a minimum of 7 (with any numbers less than 7 in length have leading 0's). And then have anything greater than 7 in length just extend the formatting so I could get an order number like Z12345678-001?
how can I keep the same formatting (i.e. Z 1234567 - 000) but have the first set of numbers (the 1-7) be a minimum of 7 (with any numbers less than 7 in length have leading 0's). And then have anything greater than 7 in length just extend the formatting so I could get an order number like Z12345678-001?
Use exactly the code that you have, because that's what it does.

Database to DataGridView floating point error or non-trimmed trailing zeros

My current project requires displaying some numbers in a DataGridView column in a Windows Forms front end. The numbers can then be editted and are sent back to the database to be updated. All values are between 0 and 0.5. For the user's sake, I wish all trailing zeros to be removed, but accuracy is also important so a value of 0.123456789 should be stored to full precision.
I had been using a SQL float to store the numbers, passing them to doubles in C#. This would result in the correct output, with trialing zeros removed (e.g. 0.2, 0.123, 0.432105). The problem was that some values were being inaccurately passed (e.g. 0.208 was being returned as 0.2080000002) due to a floating point error.
To solve this, I changed to using decimal data types in both the database and the front end. However, all values are now displayed to the maximum number of defined decimal places (eg. 0.200000, 0.123000, 0.432105).
The possible solutions I can see are:
Removing trialing zeros from the decimal in the DataGridView.
Though,
dataGridView.Columns[0].DefaultCellStyle.Format = "0.#"
doesn't appear to work.
Passing the number accurately to a C# double, which will then automatically display the number in my preferred format.
though, I am unable to achieve either of these.
Is anyone able to assist me with this problem?
private char[] _noZero = new char[] {'0'};
textBox1.Text = l.fieldOfDecimalType.ToString().TrimEnd(_noZero);

How can I format a number but show all digits of precision?

When a user goes to edit a number, I want to format a number to have a thousands separator in one case (and a percentage sign in another) but I want to be able to show absolutely all available digits of precision.
When the number is being displayed, its format is simply {0:0,0;-0,0; - }, (or {0:0,0.00;-0,0.00; - } to show two decimal places), but when my control goes into edit mode, I want to switch to displaying something very similar, but showing all available digits of precision. Is there any way to do this short of creating a format string that looks like this?
{0:0,0.#############################;-0,0.###...
I want to do something similar with percentages. I want to displayed value to be {0:0.00 %;-0.00 %; - } until the user activates the cell for editing, at which time the format should still be a percentage, but showing more digits of precision if they exist in the underlying value.
Thanks
This question is similar to yours. (The answer is that it's not possible with the .NET built-in custom numeric formatting.)

Using masked text box to validate input

Hi I am using the following mask string to ensure user enters a valid phone no
(99)-00000000
which should work fine for mobile as well as regional land line numbers in Australia
However I have encountered a problem that User can get away without entring all the digits
I understand that 9 represents an optional digit between 0 and 9 and 0 represents a required digit between 0 and 9
So how come if I dont enter all last eight mandatory digits the program still display results like
(03)-6474
(03)- 63799
(02)-1 38 390
Because it's simply filling in the blanks from left to right as you type. Even though the first two digits are optional, it fills them in like you've entered them with the first two numbers that you type.
If you dislike this behavior, you can easily subclass the MaskedTextBox control and customize how it handles keyboard input. Here are a couple of sample controls that cause the numbers to push in from right to left, as expected:
http://www.codeproject.com/KB/edit/Cool_Phone_Number_Box.aspx
http://www.dotnetheaven.com/Uploadfile/mgold/MaskedCurrencyTextBox02252006005553AM/MaskedCurrencyTextBox.aspx
(I think the second example does a better job of explaining exactly what changes are being made to the base control, plus it allows you to see most of the relevant code without downloading the sample project.)

Categories