Difference between revisions of "Formatting Numbers"

From Microstation VBA Wiki
Jump to: navigation, search
(Created page with 'The best way to format numbers for output is to use the Format() function. It seems to work fine on either a string that looks like a number or just a regular number. Here is a …')
 
Line 1: Line 1:
The best way to format numbers for output is to use the Format() function. It seems to work fine on either a string that looks like a number or just a regular number.
+
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.
  
 
Here is a simple use of Format() to show two decimal places:
 
Here is a simple use of Format() to show two decimal places:
Line 6: Line 6:
 
strText = "EL. " & Format(elev, "###0.00")
 
strText = "EL. " & Format(elev, "###0.00")
 
EL. 1040.25
 
EL. 1040.25
 +
EL. 4.25
 +
EL. 0.80
 
</PRE>
 
</PRE>
  
Line 11: Line 13:
  
 
<PRE>
 
<PRE>
strText = "STA. " & Format(sta, "##+#0.00")
+
strText = "STA. " & Format(sta, "#0+00.00")
 
STA. 35+52.00
 
STA. 35+52.00
 +
STA. 0+08.15
 
</PRE>
 
</PRE>

Revision as of 17:27, 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 represents 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