This is a migrated thread and some comments may be shown as answers.

[Solved] Decimal point problems using

5 Answers 397 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stanislav
Top achievements
Rank 1
Stanislav asked on 16 Nov 2010, 03:21 PM
 

Hi,

First of all congratulations for releasing Telerik Extensions for ASP.NET MVC 2010 Q3, it has some nice and valuable fixes and features.

But I'm experiencing problems using NumericTextBox with a decimal! In my model I want to store the value as an int (in centimeters for example), but display it with a decimal point after the second digit (displayed in meters). That is why I am dividing by 100. I have a custom filter for that action, so that it stores the values in int removing any commas.

Now the problem is that the decimal point is lost. JavaScript adds a decimal point and two zeroes after the number. But if I disable JavaScript only whole(integer) numbers are displayed.

Also another behavior I'm noticing is that when I click on the box, those two zeroes and the comma are lost. When I move to the next textbox, two more zeroes plus a comma are appended at the end of what I have typed, no mather if I have used a comma or not. So just by moving in and out of the box the number is growing and growing.

<% Html.Telerik().NumericTextBox<decimal>()
                        .Name("project.Detail.Length")
                        .Value((decimal)((decimal)Model.project.Detail.Length / (decimal)100))
                        .NumberGroupSize(0)
                        .DecimalSeparator(",")
                        .DecimalDigits(2)
                        .Spinners(true)
                        .Render();
%>

Now I suppose it is me who is doing something terribly wrong, but I can't find out what. In the master page I have:

 

 

<%= Html.Telerik().ScriptRegistrar()
%>

And an inline script after it. Adding .Globalization(true) just makes things worse. Firebug says there is a bug in "telerik.textbox.min.js" even without globalization. I can't say where exactly since the script is one line. IE 8 does not complain and the pages work slow in Opera 10.61. I have installed Telerik Extensions from the binary of 2010 Q3 and I'm using Visual Web Developer Express 2010.

Please any help will be highly appreciated!

Thank You,
Stanislav

5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 17 Nov 2010, 07:57 AM
Hi Stanislav,

 I couldn't understand what the exact problem is. Could you please attach a sample project and let us know what steps to take in order to reproduce that problem? Thanks.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Stanislav
Top achievements
Rank 1
answered on 17 Nov 2010, 08:16 AM
I found the problem.

Using .NumberGroupSize(0) introduces an error in the JavaScript, something in the textbox() function in "telerik.textbox.min.js". This error makes the page unusable. Maybe there is another way to disable grouping.

Now I'm using .DecimalSeparator(","), because of the way decimals come from the model. If I leave it as default (a dot) the comma is ignored and a .00 is added at the end.

Comma is also group separator by default, which also leads to an error when focus is moved out of the textbox, because JavaScript adds another ,00 at the end. It thinks all commas before that are group separators, not exactly a bug but a little bit unexpected. So if I'm using .DecimalSeparator(",") together with .NumberGroupSeparator(" ") and not .NumberGroupSize(0) everything is just fine.

All the best!
Stanislav
0
Atanas Korchev
Telerik team
answered on 17 Nov 2010, 08:18 AM
Hello Stanislav,

 We would really like to fix that issue and will appreciate if you send us a sample application which reproduces the JavaScript error. Thanks!

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Stanislav
Top achievements
Rank 1
answered on 17 Nov 2010, 08:50 AM
0
Georgi Krustev
Telerik team
answered on 17 Nov 2010, 04:48 PM
Hello Stanislav,

Thank you for the attached project.

I was able to investigate the problem when set .NumberGroupSize(0). I am glad to inform you that this issue was fixed and the fix will be included in the next official release of the Telerik Components for ASP.NET MVC.

For your convenience I have attached modified telerik.textbox.min.js file.

As far as second issue, it is caused by setting decimal separator to ",". Thus the decimal separator and the group separator are same and the numericTextBox UI components start to behave incorrectly. In order to avoid this issue I will suggest you declare numericTextBox component like so:
<% Html.Telerik().NumericTextBoxFor(x => x.Decimal2)
                         .DecimalSeparator(",")
                         .NumberGroupSeparator("")
                         .Render();
%>
You need to set different group separator.

I have also updated your Telerik points for the bug report.

Sincerely yours,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
NumericTextBox
Asked by
Stanislav
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Stanislav
Top achievements
Rank 1
Georgi Krustev
Telerik team
Share this question
or