Formatting
msdn - dwhawy9k
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 | |
; | |
\ | |
…' | |
"…" |
© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrev