Formatting Numbers

From Microstation VBA Wiki
Revision as of 17:27, 16 August 2010 by Ted (talk | contribs)
Jump to: navigation, search

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