FormatNumber$() function - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

Purpose

Returns a string representing a number, including thousands separators and decimal-place separators that match the user's system configuration. You can call this function from the MapBasic window in MapInfo Pro.

Syntax

FormatNumber$( num, precision ) 

num is a numeric value or a string that represents a numeric value, such as "1234.56".

precision formats a float number as per the precision. Minimum value is 6 and maximum value is 14. (This parameter will only work when input type is float or decimal.)

Return Value

String

Description

Returns a string that represents a number. If the number is large enough to need a thousands separators, this function inserts thousands separators. MapInfo Pro reads the user's system configuration to determine which characters to use as the thousands separator and decimal separator.

Examples

The following table demonstrates how the FormatNumber$() function with a comma as the thousands separator and period as the decimal separator (United States defaults):

Function Call Result returned
FormatNumber$("12345.67")
"12,345.67" (inserted a thousands separator)
FormatNumber$("12,345.67")
"12,345.67" (no change)
FormatNumber$(1234.5678, 6)
"1234.57"
FormatNumber$(1234.5678, 7) 
"1234.568"

If the user's computer is set up to use period as the thousands separator and comma as the decimal separator, the following table demonstrates the results:

Function Call Result returned
FormatNumber$("12345.67")
"12.345,67" (inserted a thousands separator, and changed the decimal separator to match user's setup)
FormatNumber$("12,345.67")
"12.345,67" (changed both characters to match the user's setup)

See Also:

DeformatNumber$() function