Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Difference between revisions of "Microsoft KB Archive/170550"

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
 
Line 67: Line 67:
 
== MORE INFORMATION ==
 
== MORE INFORMATION ==
  
A common use of the Format function is to format numbers for a consistent display. To do this, two parameters are passed to Format. The first parameter is any valid numeric expression, such as 5555.5, &quot;5555.5,&quot; etc. The second parameter is a format expression, such as &quot;###,###.00.&quot;<br />
+
A common use of the Format function is to format numbers for a consistent display. To do this, two parameters are passed to Format. The first parameter is any valid numeric expression, such as 5555.5, "5555.5," etc. The second parameter is a format expression, such as "###,###.00."<br />
 
<br />
 
<br />
The key point of emphasis is this: if the first parameter is a string representation of a number, such as &quot;5555.5,&quot; Format expects it to be in the proper regional setting as portrayed in Control Panel / Regional Settings. However, Format always expects the second parameter to be in the &quot;English (United States)&quot; setting.<br />
+
The key point of emphasis is this: if the first parameter is a string representation of a number, such as "5555.5," Format expects it to be in the proper regional setting as portrayed in Control Panel / Regional Settings. However, Format always expects the second parameter to be in the "English (United States)" setting.<br />
 
<br />
 
<br />
For example, if the regional setting is such that the decimal symbol is &quot;,&quot; and the digit grouping symbol is &quot;.&quot;, the following will occur:
+
For example, if the regional setting is such that the decimal symbol is "," and the digit grouping symbol is ".", the following will occur:
 
<div class="indent">
 
<div class="indent">
  
Format(5555.5, &quot;###,###.00&quot;) returns &quot;5.555,50&quot;<br />
+
Format(5555.5, "###,###.00") returns "5.555,50"<br />
Format(&quot;5555,5&quot;, &quot;###,###.00&quot;) returns &quot;5.555,50&quot;<br />
+
Format("5555,5", "###,###.00") returns "5.555,50"<br />
Format(&quot;5.555,5&quot;, &quot;###,###.00&quot;) returns &quot;5.555,50&quot;<br />
+
Format("5.555,5", "###,###.00") returns "5.555,50"<br />
 
<br />
 
<br />
Format(&quot;5555.5&quot;, &quot;###,###.00&quot;) returns &quot;55.555,00&quot;<br />
+
Format("5555.5", "###,###.00") returns "55.555,00"<br />
Format(&quot;5,555.5&quot;, &quot;###,###.00&quot;) returns &quot;5,56&quot;
+
Format("5,555.5", "###,###.00") returns "5,56"
  
  
 
</div>
 
</div>
With the regional setting as described above, the number 5555.5 and the string &quot;5555.5&quot; are interpreted quite differently by Format.
+
With the regional setting as described above, the number 5555.5 and the string "5555.5" are interpreted quite differently by Format.
  
 
</div>
 
</div>

Latest revision as of 11:05, 21 July 2020

Knowledge Base


INFO: Format Function and International Settings

Article ID: 170550

Article Last Modified on 1/20/2007



APPLIES TO

  • Microsoft Visual Basic 5.0 Control Creation Edition
  • Microsoft Visual Basic 5.0 Learning Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 4.0 Standard Edition
  • Microsoft Visual Basic 4.0 Professional Edition
  • Microsoft Visual Basic 4.0 Professional Edition
  • Microsoft Visual Basic 4.0 16-bit Enterprise Edition
  • Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
  • Microsoft Access 1.1 Standard Edition
  • Microsoft Access 2.0 Standard Edition
  • Microsoft Access 95 Standard Edition
  • Microsoft Access 97 Standard Edition
  • Microsoft Excel 5.0 Standard Edition
  • Microsoft Excel 97 Standard Edition
  • Microsoft Word 97 Standard Edition
  • Microsoft Excel 95 Standard Edition



This article was previously published under Q170550

SUMMARY

The Format function does not always return the expected number format with certain international settings. This article explains this behavior and describes how the Format function interprets its parameters.

MORE INFORMATION

A common use of the Format function is to format numbers for a consistent display. To do this, two parameters are passed to Format. The first parameter is any valid numeric expression, such as 5555.5, "5555.5," etc. The second parameter is a format expression, such as "###,###.00."

The key point of emphasis is this: if the first parameter is a string representation of a number, such as "5555.5," Format expects it to be in the proper regional setting as portrayed in Control Panel / Regional Settings. However, Format always expects the second parameter to be in the "English (United States)" setting.

For example, if the regional setting is such that the decimal symbol is "," and the digit grouping symbol is ".", the following will occur:

Format(5555.5, "###,###.00") returns "5.555,50"
Format("5555,5", "###,###.00") returns "5.555,50"
Format("5.555,5", "###,###.00") returns "5.555,50"

Format("5555.5", "###,###.00") returns "55.555,00"
Format("5,555.5", "###,###.00") returns "5,56"


With the regional setting as described above, the number 5555.5 and the string "5555.5" are interpreted quite differently by Format.

Keywords: kbinfo kbprogramming KB170550