Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

How can I format an 8 byte floating point number to a currency value of two decimal places?

How can I format an 8 byte floating point number to a currency value of two decimal places?

Note that a float is an 8 byte data type that represents an 8-byte floating-point value, therefore if you specify 5.5, it will be interpreted as 5.500000 by Silk Performer Runtime.

In order to make a float appear with two decimal places it must first be converted to a string; then you will need to use the string manipluation function "SubStr" to extract the string to the second decimal point. Please note that special consideration needs to be taken when specifying the fourth parameter "nLen" of the “SubStr”. For example if the floating point number is: "fTemp := 5500.000;" then the nLen specified would need to be 7, like so: Substr(sTemp, sTemp1, 1, 7);

Below is example BDL code which demonstrates how to do this:

fTemp := 5.500000;

writeln(fTemp);
sTemp := string(fTemp);
writeln(sTemp);
Substr(sTemp, sTemp1, 1, 4);
writeln(sTemp1);

Output:

5.500000
5.500000
5.50
Final Formatted String = 5.50

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 19:08
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.