0

Currently i've a following Scenario :

I've a custom control for Numeric Input. Which have the Property called : DecimalType. Which might be Long or Short Decimal.

And, the Problem is : I want to Format the Given input as Common. Which either format the Current input in 2 decimal Digits (Short) or 4 decimal Digits(Long) by using the Current Culture.

I can setup only one format on the Current Culture.

Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalDigits = 2;

or

Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalDigits = 4;

So, in my situation, how do i handle this efficiently? Because, in a single form there might be 2 short decimal textboxes and 4 long decimal textboxes. By changing NumberDecimalDigits to 2 will not work for long decimal or vice-versa.

In Short : The Text should be formatted according to the Current Culture with the 2 custom decimal length.

Any suggestions that i can follow to handle those things?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
N Subedi
  • 2,858
  • 2
  • 22
  • 36

1 Answers1

0

There are two options here. (1) use an explicit custom number format pattern with the number of decimal digits -- something like #,0.00 and #,0.0000 -- or (2) don't rely on the CurrentCulture at all. All the formatting functions allow you to explicitly provide a CultureInfo object so you can have one for each.

Personally, I would use option 1.

Community
  • 1
  • 1
Eric MSFT
  • 3,246
  • 1
  • 18
  • 28