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 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.

# 
0 
. 
, 
% 
E+000 
E-000 
; 
\ 
' 
"" 



© 2020 Better Solutions Limited. All Rights Reserved. © 2020 Better Solutions Limited TopPrev