Forum Moderators: open

Message Too Old, No Replies

Decimal Places

         

zxk105

3:31 pm on Jan 18, 2005 (gmt 0)

10+ Year Member



I am using VB.NET and I am trying to force 2 decimal places when writing out my results. I am using 'Double' when initializing my variables. They are stored as integers in the database though. I am also using Decimal.Round(num, 2) but it's not helping.

This is what I am trying to achieve:

2.45454545 --> 2.45
2.45 --> 2.45
2.4 --> 2.40
2 --> 2.00

CaseyRyan

4:12 pm on Jan 18, 2005 (gmt 0)

10+ Year Member



You can use the FormatNumber [msdn.microsoft.com] function in VB.

Dim oldValue as String
Dim newValue as string
oldValue = "2.45454545"
newValue = FormatNumber(oldValue, 2, , , TriState.False)

newValue now equals "2.45"

Another function you may like is FormatCurrency [msdn.microsoft.com].

-=casey=-

zxk105

4:29 pm on Jan 18, 2005 (gmt 0)

10+ Year Member



Thanks! It worked....