objNumberFormatInfo = New System.Globalization.NumberFormatInfo 
objNumberFormatInfo.NumberDecimalSeparator = "."

Converting Scientifc/Floating into double

dbValue = System.Double.Parse("4.5E8",Globalization.NumberStyles.Float, objNumberFormatInfo) 

dbValue = 1234567 
dbValue.ToString("#,#") = 1,234,567

Formatting Numbers

Dim sResult As String 
sResult = System.String.Format("Total is {0}", 123.45)
sResult = "The total is 123.45"

When the argument is numeric you can add a colon after the argument index followed by a character to specify the numerical format.

sResult = System.String.Format("Total is {0:C}", 123.45) 
sResult = "The total is $123.45"

You can also append an integer after the argument index to indicate the number of decimal places.

sResult = System.String.Format("Total is {0:C1}", 123.45) 
sResult = "The total is $123.5"
G or gGeneral - Displays the number in either fixed-point or exponential format depending on which format delivers the most compact result.
N or nNumber - This includes the thousand separator.
C or cCurrency
D or dDecimal - Only works with Integer values.
E or eScientific - Displays the number as n.nnnnE+eeee
F or fFixed-point
P or pPercent - Displays the number as a percentage with decimal places as default.
R or rRound-trip
X or xHexadecimal

You can also build you own custom number format by using any of the following special characters.


Adding Leading Zeros

dbValue = 25 
sValue = dbValue.ToString.PadLeft(4,"0"c)
Do While (dbValue <= 200)
   dbValue = dbValue + 50
   sValue = dbValue.ToString.PadLeft(4,"0"c)

© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext