ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Your version: XXA250083N

The content of this page has been updated to version 26.  See documentation 26 now.
Help / WLanguage / WLanguage functions / Standard functions / Functions for managing strings
  • Detailed format of the character string to obtain
  • Limits
  • Conversion into bytes
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Transforms a numeric value (integer, real or currency) into a character string according to the specified format.
PHP In this version, the numeric value to transform must be an integer or a real.
Example
NumToString(123) // Returns "123"
NumToString(1.23) // Returns "1.23"
NumToString(12345.5, "+10.2f") // Returns " +12345.50"
NumToString(12345.5, "-+10.2f") // Returns "+12345.50 "
NumToString(12345.5, "+010.2f") // Returns "+012345.50"
NumToString(12345.5, "010.2f") // Returns "0012345.50"

NumToString(12345.5, "10.2fS")
// Returns " 12 345.50" (the thousand separator is " ")

NumToString(12345.5, "10,2fS")
// Returns " 12 345,50" (the decimal separator is ",")
Syntax
<Result> = NumToString(<Number> [, <Format>])
<Result>: Character string
Number expressed in character string format according to the selected format.
If <Number> is a string, this string is returned as it is. The format is ignored.
PHP If <Number> is a string, this string is transformed as if it was a number.
<Number>: Integer or real
Numeric value to convert into a character string (according to the specified format).
<Format>: Optional character string or constant
  • Format of character string, expressed in the following format:
    "[<Alignment>][<Sign>][<Zero>][<Size>][<.Precision>]<Type>[<Thousand>]"

    PHP The string is expressed in the following format:
    "[<Zero>][<Alignment>][<Size>][<.Precision>]<Type>"

    See remarks for more details.
  • WINDEVWEBDEV - Server codeiPhone/iPadUniversal Windows 10 AppWindows Mobile Constant used to define a system format:
    maskSystemCurrencyUse the currency mask of the system.
    maskSystemNumeralUse the numeric mask of the system.
Remarks

Detailed format of the character string to obtain

To convert a numeric value into a string, you need to specify the format of the string you want to get. This format is described as follows:
"[<Alignment>][<Sign>][<Zero>][<Size>][<.Precision>]<Type>[<Thousand>]"
PHP The format is described as follows:
"[<Zero>][<Alignment>][<Size>][<.Precision>]<Type>"
The possible values are as follows:
<Alignment>If this parameter is specified, justifies the number to the left (<Alignment> = "-").
The number is justified to the right by default.
<Sign>If this parameter is specified, forces the sign for the positive numbers (<Sign> = "+"). This sign will appear on the left of the first significant number.
By default, only the negative numbers have a "-" sign on the left of the first significant number.
Special case: if this parameter is specified and if the number is equal to 0, the "+" sign will be displayed. Same if a negative number becomes equal to 0.
<Zero>If this parameter is specified (<Zero> ="0"), the number will be completed with zero on the left of the first significant number if the significant part of the number is smaller that the requested size and the number is right justified.
By default, the number is not filled with "0".
For example: NumToString(123, "05d") will return "00123".
<Size>Defines the total length of the result string. The total length corresponds to the following elements: sign, thousand separator, decimal point, exponent, integer and decimal parts of the number. This size must be less than 100.
If the specified size is too small to contain the significant part of the number, it will be ignored.
By default, the number will have the size of its significant part (it cannot be filled with zeros). Same if <Size> = 0.
If the specified size is greater than the significant part of the number:
  • the result string will be filled with space characters on the right if the number is justified to the left,
  • the result string will be filled with space characters or zeros on the left if the number is justified to the right.
PHP Defines the total length of the result string or the total length of the integer part if the number is filled with zeros. The total length corresponds to the following elements: sign, thousand separator, decimal point, exponent, integer and decimal parts of the number.
If the specified size is too small to contain the significant part of the number, it will be ignored.
By default, the number will have the size of its significant part (it cannot be filled with zeros). Same if <Size> = 0.
If the specified size is greater than the significant part of the number:
  • the result string will be filled with space characters on the right if the number is justified to the left,
  • the result string will be filled with space characters or zeros on the left if the number is justified to the right.
<.Precision>Defines the decimal separator ("." or "," characters) and the number of decimal places (for the float ("f") and exponent ("e") <Types> only).
The decimal separator:
  • If the decimal separator is a comma, the decimal separator will be the one defined:
    • in the linguistic parameters of Windows.
    • WEBDEV - Server code in the Windows configuration of the server.
    • iPhone/iPad for the current user.
  • If the decimal separator is a dot, the decimal separator used will be a dot.
Notes:
  • ChangeSeparator has no effect on this separator. Indeed, this function acts on the display mask of numeric values in the controls.
  • WEBDEV - Browser code The <,Precision> syntax cannot be used: you must use <.Precision>.
Number of decimals:
  • The number of decimal places must be less than 100.
  • If the number of decimal places in the number is greater than <Precision>, the decimal part is rounded to the specified number of decimal places.
  • If the number of decimals in the number is less than <Precision>, the decimal part is filled with "0" to the right.
  • The value of <Precision> can be greater than <Size>. In this case, <Size> is ignored.
PHP Defines the number of decimals (for the float ("f") and exponent ("e") <Types> only).
  • If the number of decimal places in the number is greater than <Precision>, the decimal part is rounded to the specified number of decimal places.
  • If the number of decimals in the number is less than <Precision>, the decimal part is filled with "0" to the right.
  • The value of <Precision> can be greater than <Size>. In this case, <Size> if ignored if the number is filled with space characters.
<Type>Type of the result, mandatory parameter:
  • d: Integer:
    A real number will be rounded to the nearest integer.
  • e: Exponential notation:
    If <Precision> is not indicated, 6 digits by default.
  • f: Decimal notation:
    If <Precision> is not indicated, 6 digits by default.
  • x and X: Hexadecimal notation (X for uppercase letters):
    Only the integer part of the number is taken into account (no rounding).
    Special case:
    1. Size not specified and negative number: 20 hexadecimal characters for a currency, 8 characters for all the other numeric types.
    2. Negative number: the size of the result string will be at least the size allowing to specify the sign bit.
    For example: -32767 if the "3X" format will return "8001"
  • o: Octal notation:
    Only the integer part of the number is taken into account (no rounding).
    Special case:
    1. Size not specified and negative number: 27 hexadecimal characters for a currency, 11 characters for all the other numeric types.
    2. Negative number: the size of the result string will be at least the size allowing to specify the sign bit.
    For example: -32767 in the "3o" format will return "700001"
<Thousand>Thousand separator (<Thousand> = "S" or "s"). The digits found in the integer part of the number will be grouped by 3 and separated by the thousands separator defined in Windows. If the sign is present, it will always be displayed immediately to the left of the first significant digit. No thousands separator can be found between the sign and the first digit.
WEBDEV - Browser code The thousands separator is always a space character (' ').
WINDEVWEBDEV - Server codeWEBDEV - Browser codeReports and QueriesiPhone/iPadUniversal Windows 10 AppWindows MobileAjaxUser code (UMC)

Limits

  • The "f" format returns a valid result for numbers included between -1e+17 and 1e+17.
  • "x", "d" or "o" formats: the integer part must not exceed 99 999 999 999 999 999.
  • WEBDEV - Server code How to use a comma for the decimal separator?
    If the Windows configuration on the server is not using a comma as decimal separator, you have the ability to:
    • use a numeric edit control (hidden if necessary). The displayed value can be retrieved by ..DisplayedValue.
    • use a Formatted Display control.

Conversion into bytes

To convert a size into bytes, use LengthToString.
Component : wd250std.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Como mostrar pontos e virgula
cyTotal_aberto is currency=10600385.15
STC_TOTAL+=" Aberto:"+NumToString(cyTotal_aberto,"10,2fS") // "10,2f"
//RESULTADO SERA: 10.600.385,15
amarildo
16 Mar. 2020

Last update: 10/31/2019

Send a report | Local help