|
|

Available Now

Search

Contact
Feedback:
Send an e-mail with your
comments about this program (or anything else).

Help support DFF
If you benefit from the website, in terms of
knowledge, entertainment value, or something otherwise useful,
consider making a donation via PayPal to help defray the
costs. (No PayPal account necessary to donate via credit
card.) Transaction is secure.


|
| |
Programs that use floating point numbers (i.e. with decimal points), need some special
considerations to work correctly in countries whose decimal separator is not a
dot, "." or that reads string versions of numbers generated by systems
whose decimal separator does not agree with the user's system.
Here are three tips for the programmer to avoid problems:
- Always use the DecimalSeparator global variable rather than '.' or
',' when checking input or creating output string versions of
floating point numbers.
- Do not use the system Val procedure to convert strings to floating point numbers numbers.
Val assumes that the decimal separator is a dot (.). The formatting
procedure StrToFloat does handle decimal separator values correctly.
This program contains a replacement Val procedure which uses StrToFloat to correctly recognize the current separator.
- If numeric floating point strings are written to text files, include a line identifying the decimal separator used. At input
time, replace that character with the current decimal separator for the system reading the file.
Here's a program, DecimaSep, than incorporates all three tips including a replacement for
Delphi's "Val" procedure for testing.
Addendum December 3, 2008: A viewer recently pointed out that the
handling of decimal separators should also be prepared to handle the thousands
separator since the US usage (x,xxx.xx) has the separator roles reversed in most
of Europe (x.xxx,xx). DecimalSep2 addresses this with two changes.
- My Val procedure now ignores any embedded Thousandseparator
characters in the input string.
- When writing the decimal separator header record to a file with text
numeric data, both decimal and thousands separators are saved. When
reading the file back, the thousands separator, if present, is used to
modify any occurrences found to the appropriate thousands separator
character for the current locale.
Click here to download
International Decimal Demo source code
| Created: March 12, 2005 |
Modified:
November 07, 2008 |
|