PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • 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.
Versions 15 and later
Android This function is now available for the Android applications.
New in version 15
Android This function is now available for the Android applications.
Android This function is now available for the Android applications.
Versions 17 and later
iPhone/iPad This function is now available for the iPhone/iPad applications.
New in version 17
iPhone/iPad This function is now available for the iPhone/iPad applications.
iPhone/iPad This function is now available for the iPhone/iPad applications.
Versions 18 and later
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
New in version 18
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
Versions 21 and later
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
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.
  • Versions 17 and later
    WINDEVWEBDEV - Server codeiPhone/iPadWindows MobileUniversal Windows 10 App Constant used to define a system format:
    maskSystemCurrencyUse the currency mask of the system.
    maskSystemNumeralUse the numeric mask of the system.
    New in version 17
    WINDEVWEBDEV - Server codeiPhone/iPadWindows MobileUniversal Windows 10 App Constant used to define a system format:
    maskSystemCurrencyUse the currency mask of the system.
    maskSystemNumeralUse the numeric mask of the system.
    WINDEVWEBDEV - Server codeiPhone/iPadWindows MobileUniversal Windows 10 App 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/iPadWindows MobileUniversal Windows 10 AppAjaxUser 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

Versions 16 and later
To convert a size into bytes, use LengthToString.
New in version 16
To convert a size into bytes, use LengthToString.
To convert a size into bytes, use LengthToString.
Components
WINDEVWEBDEV - Server codeReports and Queries wd230std.dll
Windows Mobile wp230std.dll
WEBDEV - Browser code WDJS.DLL
Java wd230java.jar
Linux wd230std.so
Android wd230android.jar
Minimum required version
  • Version 9
This page is also available for…
Comments
Exemplo de uso do NumToString
info(NumToString(1,"000002.00f")) = 000001

info(NumToString(1.20,"000002.00f")) = 000001.20
adrianoboller
Dec. 06 2016
IntegerToString
PROCEDURE IntegerToString(Texto)

//Texto = "065100114105097110111032066111108108101114"

sNovoTexto, sNovo is string = ""

IF Texto <> "" THEN

nTotal is int = Length(Texto) / 3
nPos is int = 1

LOOP (nTotal)

sNovo = Middle(Texto, nPos, 3)

sNovoTexto += Charact( sNovo )

nPos += 3

END

END

//sNovoTexto = "Adriano Boller"

RESULT sNovoTexto
BOLLER
Dec. 06 2016
StringToInteger
PROCEDURE StringToInteger(Texto)

//Texto = "Adriano Boller"

sNovoTexto is string = ""

IF Texto <> "" THEN

nTotal is int = Length(Texto)
nPos is int = 0

LOOP (nTotal)

nPos += 1

sNovoTexto += NumToString( Asc( Middle(Texto, nPos, 1) ), "03.00f" )

//A = 065

//d = 100...

END

END

//sNovoTexto = "065100114105097110111032066111108108101114"

RESULT sNovoTexto
BOLLER
Dec. 06 2016