i'm building app using kendo (v. 2019.2.514). And i have strange error with number format by NumericTextBox.
At this moment i'm creating a form to modify products. Problem is that, i'm getting different results for my values.
Values are stored in database as floats. In model as well. And i'm pretty sure that problem is with the format because when value is a natural number it's fine, but:
(first control format)
0.1 gives 1
0.05 gives 5
(2nd format)
1.2 gives 120000004768372 (which means the original value was multiplied by 1e+14)
0.3 gives 300000011920929 (* 1e+15)
that are my 2 kinds of NumericTextBox formats
@(Html.Kendo().NumericTextBox<float>().Name("Weight").Min(0).Value(Model.Weight).Format("#.## kg")
.Placeholder($"{Language.translate("Weight")} (kg)").HtmlAttributes(new { validate = true })
)
@(Html.Kendo().NumericTextBox<float>().Name("upTo7").Min(0).Format("#.## €").Value(Model.Price)
.Placeholder(Language.translate("Price up to x days").Replace("x", "7")).HtmlAttributes(new { validate = true })
)
I've already tried formats like #.00, n2 and nothing works for me
I just want to display these numbers properly
The problem seems to be in with your Model because I just tried the following code and it works fine:
@(Html.Kendo().NumericTextBox<float>().Name("Weight").Min(0).Value(0.05f).Format("#.## kg")
.Placeholder("Weight (kg)").HtmlAttributes(new { validate = true })
)
@(Html.Kendo().NumericTextBox<float>().Name("upTo7").Min(0).Format("#.## €").Value(1.2f)
.Placeholder("Price up to 7 days").HtmlAttributes(new { validate = true })
)
Output:
0.05 kg
1.2 €
I suggest using decimal
data type in your database instead of float
because approximate numeric data types do not store the exact values specified. See Difference between numeric, float and decimal in SQL Server for more details.