http://www.newton-inc.com/dev/techinfo/qa/qa.htm
sprintf
-like function for formatting numbers called FormattedNumberStr
. The Newton Programmer's Guide 2.0 First Edition (beta) says this function is no longer supported. How do I format my numbers?FormattedNumberStr
. Here is the FormattedNumberStr
API that is supported. FormattedNumberStr
should be considered to have undefined results if passed arguments other than those specified here.FormattedNumberStr(number, formatString)
Returns a formatted string representation of a real number. number
A real number. formatString
A string specifying how the number should be formatted.sprintf
. The formatString
specifies how the real number should be formatted; that is, whether to use decimal or exponential notation and how many places to include after the decimal point. It accepts the following format specifiers: %f
Use decimal notation (such as "123,456.789000"). %e
Use exponential notation (such as "1.234568e+05"). %E
Use exponential notation (such as "1.234568E+05")."%.3f"
yields "123,456.789"
for example.) FormattedNumberStr
uses the current values of GetLocale().numberFormat
to get the separator and decimal characters and settings. The example strings above are for the US English locale.formatStrings
. Previous releases of the documentation listed %g
and %G
as supported specifiers. The behavior of these specifiers has changed with the Newton 2.0 OS. Given the similarities to the sprintf
function, it may occur to you to try other sprintf formatting characters. Specifiers other than above have an undefined result and should be considered undocumented and unsupported. FormattedNumberStr
does not work properly for numbers larger than 1.0e24
. If the number is very large the function can cause the Newton device to hang.%f
with large number or a large number of digits following the decimal, FormattedNumberStr
has undefined results, and can cause the Newton device to hang. FormattedNumberStr
does not guarantee which direction it will round. In the Newton 2.0 OS, it rounds half cases down rather than up or to an even digit. If you need a precisely rounded number you should use the math functions Ceiling
, Floor
, NearbyInt
, or Round
with suitable math.FormattedNumberStr
that caused a trailing decimal character to be added when zero decimal positions was specified. That is, FormattedNumberStr(3.0, "%.0f")
resulted in "3."
not "3"
. To properly test for and remove this unwanted extra character you must be sure to use the character specified in the Locale settings and not assume the decimal character will be a period.