NumberToText
New to Analytica 4.5
Note: A preliminary version is included in patch release 4.4.3, but not exposed on menus or in the User Guide. The function included with 4.4 is subject to change.
NumberToText( x, format, digits, showZeroes, separators, currency, dateFormat, fullPrecision )
Convert a number (or date-time number) to text with explicit control over the number format settings. The parameters are similar to those found on the Number Format Dialog.
When «x» is a non-numeric value (text, Null, Handles, References, etc., then the value of «x» is returned without modification.
Prior to the introduction of this function, you would need to concatenate text to the number, e.g., "" & x, during which the number format for the current object controls how the resulting number is formatted (see coercing numbers to text). This remains a perfectly good way to coerce numbers to text, but NumberToText provides yet another option, with some new flexibility. If you are using a pre-4.5 release, you should continue to use the concatenation method.
Parameters
- «format»
- The type of format used for numbers (but not date or date/time values). It can be one of the following values (or just the first letter):
- "Suffix" (39.63K)
- "Exponential" (3.963e+004)
- "Fixed Point" (39632.55)
- "Integer" (39633)
- "Percent" (3963254.89%)
- "Date" (4-Jul-2012) -- forces numbers to display as dates
- "Boolean" (True)
- "Hexadecimal" (0x9ad1)
- «digits»
- The number of significant digits for Suffix and Exponential formats, or the number of digits to the right of the decimal point for Fixed Point and Percent formats.
- «showZeroes»
- Boolean specifying whether to show training zeroes.
- «separators»
- Boolean specifying whether to show separators. In the US, this would be commas between each group of three digits (e.g., 39,632.55).
- «currency»
- Specifies the currency symbol to display, or the symbol and its placement relative to the digits and sign. The following placement templates recognized, where the
$can be replaced by any currency symbol.
- "$-#"
- "$#-"
- "-$#"
- "-#$"
- "#$-"
- "#-$"
- "(#$)"
- "($#)"
- "regional"
- Specifies the currency symbol to display, or the symbol and its placement relative to the digits and sign. The following placement templates recognized, where the
- «dateFormat»
- The template used to display dates, times, or date-time numbers. The following patterns are substituted, and anything else is printed literally.
- "SHORT", "ABBREV", "LONG", "TIME", "DATETIME": regional-specific standard formats.
- y, yy, yyyy: The year. y=two digit, no leading zero. yy=two digits. yyyy=four digits.
- M, MM: The month number, without or with leading zero.
- MMM, MMMM: The month name, abbreviated or full ("Jan" or "January")
- d, dd: The day number, without or with leading zero.
- w: The weekday number
- www, wwww: The weekday name, abbreviated or full ("Wed", or "Wednesday")
- q : The quarter (1 thru 4)
- h, hh: The numeric hour from 1 thru 12, without or with leading zero.
- tt : AM or PM
- H, HH: The numeric hour from 0 thru 23, without or with leading zero.
- m, mm: The numeric number of minutes, from 0 to 59, without or with leading zero.
- s, ss: The whole number portion of seconds, from 0 to 59, without or with leading zero.
- .ssssss: The fractional seconds (up to 6 digits)
- ' literal text ': The literal text is shown. If you want the ' character to show, then you must double it.
- «fullPrecision»
- A boolean value. When set to true, the number is displayed at full precision even if this requires exceeding the number of digits specified in «digits».
Examples
NumberToText( -1234567.89012, "Fixed Point", 1 ) → "-1234567.9" NumberToText( -1234567.89012, digits:6 ) → "-1.23456M" NumberToText( 0.8, "Percent", 4, showZeroes:true ) → "80.0000%" NumberToText( -594321.342, "Fixed Point", separators:true, currency:"-# USD ) → "-594,321.34 USD" NumberToText( -594321.342, "Fixed Point", separators:true, currency:"(€#)") → "(€594,321.34)" NumberToText( 594321.342 "Fixed Point", separators:true, currency:"(€#)") → "€594,321.34" NumberToText( 594321.342, "Fixed Point", separators:true, currency:"$-#") → "$594,321.34" NumberToText( 594321.342, "Suffix", 3, currency:"£") → "£594K" NumberToText( 4-Jul-2012 13:52:03, dateFormat:"www, MMMM dd, ''''yy 'at' hh:mm tt") → "Wed, July 04, '12 at 01:52 PM"
Enable comment auto-refresher