Difference between revisions of "Formatting Numbers"

From Microstation VBA Wiki
Jump to: navigation, search
 
Line 1: Line 1:
The best way to format numbers for output is to use the Format() function. Unlike the Str() function, Format does not add an extra space in front of positive numbers. It seems to work fine on either a string that looks like a number or just a regular number. # represents a number, 0 represents a required leading or trailing zero.
+
The best way to format numbers for output is to use the Format() function. Unlike the Str() function, Format does not add an extra space in front of positive numbers. It seems to work fine on either a string that looks like a number or just a regular number. # represents a number, 0 can also be a number or a required leading or trailing zero.
  
 
Here is a simple use of Format() to show two decimal places:
 
Here is a simple use of Format() to show two decimal places:

Latest revision as of 17:28, 16 August 2010

The best way to format numbers for output is to use the Format() function. Unlike the Str() function, Format does not add an extra space in front of positive numbers. It seems to work fine on either a string that looks like a number or just a regular number. # represents a number, 0 can also be a number or a required leading or trailing zero.

Here is a simple use of Format() to show two decimal places:

strText = "EL. " & Format(elev, "###0.00")
EL. 1040.25
EL. 4.25
EL. 0.80

Stationing in surveying puts a separator after the hundreds marker so you can generate the proper format with this statement:

strText = "STA. " & Format(sta, "#0+00.00")
STA. 35+52.00
STA. 0+08.15