In the same way, if you want the number to display with less numbers on the right side of the decimal separator, specify that number. As a third alternative, you can call the Format() function. In reality, the second argument is used to format the number with many more options. To represent the integral part of a number, you use the # sign. To specify the number of digits to display on the right side of the decimal separator, type a period on the right side of # followed by the number of 0s representing each decimal place. Here is an example: Public Module Exercise Public Function Main() As Integer Dim Number As Double Number = 20502.48 MsgBox("Number: " & Format(Number, "#.00000")) Return 0 End Function End Module The five 0s on the right side of the period indicate that you want to display 5 digits on the right side of the period. This would produce: You can enter as many # signs as you want; it wouldn't change anything. Here is an example: Public Module Exercise Public Function Main() As Integer Dim Number As Double Number = 20502.48 MsgBox("Number: " & Format(Number, "##########.00000")) Return 0 End Function End Module This would produce the same result as above. To specify that you want to display the decimal separator, include its character between the # signs. Here is an example: Public Module Exercise Public Function Main() As Integer Dim Number As Double Number = 20502.48 MsgBox("Number: " & Format(Number, "###,#######.00000")) Return 0 End Function End Module This would produce: You can include any other character or symbol you want in the string to be part of the result, but you should include such a character only at the beginning or the end of the string, otherwise the interpreter might give you an unexpected result. |
|
|
|