question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NumericUpDown Exponent displayed for decimal type

See original GitHub issue

When binding a decimal? to the value of a NumericUpDown control it still formats the value like a double with showing the exponent like 5E-05 instead of 0,00005.

Doesn’t the NumericUpDown Control just use the ToString method of the value Property? Like in the example below a decimal ToString print the value with zeros not with exponent.

(0.00005).ToString()   // 5E-05
((decimal)(0.00005)).ToString()   // 0,00005

At the moment i made a workaround setting the StringFormat of the NumericUpDown controls

<Style BasedOn="{StaticResource {x:Type mah:NumericUpDown}}" TargetType="{x:Type mah:NumericUpDown}">
    <Setter Property="StringFormat" Value="0.##########################" />
</Style>

But i was woundering why the NumericUpDown control behave like that. Will the value internal be converted to a double?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
timuniecommented, Nov 10, 2019

Hi @Kabennsky at the Moment the value is converted into a double, also if you bind to a decimal. I had a short discussion with @punker76 and he explained that we cannot change the value to decimal and it will cover all types, because they have different min, max and precision: https://exceptionnotfound.net/decimal-vs-double-and-other-tips-about-number-types-in-net/

one idea was to add an enum where the user can choose the type of the value. The default would be double. At the moment this is just an idea, so will see if he gets it to work or not.

public enum ValueType
{
  Double,
  Decimal,
  Int,
  Long.
  ...
}

Happy coding Tim

0reactions
paulovilacommented, Jan 20, 2021

Is it possible to support decimal/nullable decimal so that there is no conversion to/from other numeric types?

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - .NET NumericUpDown with Decimals=AsNeeded
Simply set the number of decimal places shown by the NumericUpDown control as needed: Private Sub NumericUpDown1_ValueChanged(sender As ...
Read more >
NumericUpDown does not round to enforce DecimalPlaces
NumericUpDown would internally round to zero decimal places, using something like Math.Round(), and Value would be 2 like it shows in the text ......
Read more >
How to set the Decimal Places in the NumericUpDown ...
Int32 types, which represents the number of decimal places to display in the up-down control. It will throw an ArgumentOutOfRangeException ...
Read more >
NumericUpDown.DecimalPlaces Property
Gets or sets the number of decimal places to display in the spin box (also known as an up-down control). This property doesn't...
Read more >
Controlling input in Numeric Updown
For example, if the NUD is displaying two decimal places for currency, different people might want to set the Increment to 1 for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found