Formatting
NumberFormatInfo
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 g | General - Displays the number in either fixed-point or exponential format depending on which format delivers the most compact result. |
N or n | Number - This includes the thousand separator. |
C or c | Currency |
D or d | Decimal - Only works with Integer values. |
E or e | Scientific - Displays the number as n.nnnnE+eeee |
F or f | Fixed-point |
P or p | Percent - Displays the number as a percentage with decimal places as default. |
R or r | Round-trip |
X or x | Hexadecimal |
You can also build you own custom number format by using any of the following special characters.
# | |
0 | |
. | |
, | |
% | |
E+000 | |
E-000 | |
; | |
\ | |
…' | |
"…" |
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)
Loop
© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext