Skip to content

Commit 8073a47

Browse files
kb(numericTextbox): clarifications on scientific notation behavior from the framework
1 parent 2f77f42 commit 8073a47

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

knowledge-base/numerictextbox-scientific-format-small-numbers.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,27 @@ Use a sufficiently small number and bind it to the Numeric Textobox, then focus
3535
<TelerikNumericTextBox Decimals="6" @bind-Value="@Performance" Format="@format"></TelerikNumericTextBox>
3636
3737
@code{
38-
decimal Performance { get; set; } = 0.000070m;
38+
double Performance { get; set; } = 0.000070;
3939
4040
string format = "#0.000000";
41+
42+
protected override void OnInitialized()
43+
{
44+
//this will show the scientific notation in the console too
45+
Console.WriteLine(Performance);
46+
47+
base.OnInitialized();
48+
}
4149
}
4250
````
4351

4452
## Cause\Possible Cause(s)
53+
54+
Sufficiently small (or large) numbers may be rendered as strings by the framework in scientific notation (see the example above).
55+
4556
The Telerik Numeric Textbox renders the `Format` parameter when it is not focused through a simple `.ToString(Format)` call, but when focused, it needs to take into account the `Decimals` and so it has to round the value before calling `.ToString()` to it to render it in the input.
4657

47-
This rounding makes types with lower precision (such as `double`) show up in sceintific notation (such as `7E-05`) instead of the expected decimal notation (such as `0.000070`).
58+
This rounding makes types with lower precision (such as `double`) show up in sceintific notation (such as `7E-05`) instead of the expected decimal notation (such as `0.000070`) while the `Format` may be set to something that does not manifest this behavior and thus mask the problem.
4859

4960
You can find a sample approximation of the rounding code at the time of writing here:
5061

0 commit comments

Comments
 (0)