NumberFormatInfo Decimal Places

  • Thread starter Thread starter Mythran
  • Start date Start date
M

Mythran

The NumberDecimalPlaces property is messing me up. I have an arbitrary
number, lets say 1234.567. What do I need to do to get the following
string: $1 , 234.567...or any decimal value? Basically, I don't care if the
number has 3 or 100 decimal values, I want to display all of the decimal
digits entered. Using NumberFormatInfo, the default of NumberDecimalDigits
is 2. So the following doesn't work correctly:

Dim info As NumberFormatInfo = New NumberFormatInfo()
Dim d As Decimal = 1234.567
Dim s As String
Dim positiveFormat As String = "${0}"
Dim negativeFormat As String = "(${0})"
Dim isPositive = (d >= 0)

d = IIf(d >= 0, d, d * -1)

With info
.NumberGroupSeparator = " , "
End With

s = d.ToString(format, info)


The resulting value of s is $1,234.58, but I want to see $1,234.567. How
can I do this? The amount of digits to the right of the decimal place isn't
known until runtime. I do know I can count the digits, but is there a more
elegant solution?

Thanks,
Mythran
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top