PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
  • Detailed format of the character string to obtain
  • Limitations
  • Convert a size in 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
Converts a numeric value (integer, real or currency) to a string according to a specified format.
Versions 15 and later
Android This function is now available for Android applications.
New in version 15
Android This function is now available for Android applications.
Android This function is now available for Android applications.
Versions 17 and later
iPhone/iPad This function is now available for iPhone/iPad applications.
New in version 17
iPhone/iPad This function is now available for iPhone/iPad applications.
iPhone/iPad This function is now available for 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.
Versions 26 and later
Apple Watch This function is now available for Apple Watch applications.
New in version 26
Apple Watch This function is now available for Apple Watch applications.
Apple Watch This function is now available for Apple Watch applications.
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
String representing the number according to a specified format.
If <Number> is a string, the returned string is the same as the initial string. The format is ignored.
<Number>: Integer or real
Numeric value to convert to a string (according to the specified format).
<Format>: Optional character string or constant
  • String format expressed as follows:
    "[<Align>][<Sign>][<Zero>][<Length>][<.Precision>]<Type>[<Thousand>]"


    For more details, see the remarks.
  • Versions 17 and later
    iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile Constant used to define a system format:
    maskSystemCurrencyCurrency mask used by the system.
    maskSystemNumeralNumeric mask used by the system.
    New in version 17
    iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile Constant used to define a system format:
    maskSystemCurrencyCurrency mask used by the system.
    maskSystemNumeralNumeric mask used by the system.
    iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile Constant used to define a system format:
    maskSystemCurrencyCurrency mask used by the system.
    maskSystemNumeralNumeric mask used by the system.
Remarks

Detailed format of the character string to obtain

To convert a numeric value to a string, you need to specify the format of the string to be obtained. The format is as follows:
"[<Align>][<Sign>][<Zero>][<Length>][<.Precision>]<Type>[<Thousand>]"
The possible values are:
<Align>If this parameter is specified, forces the number to be left-aligned (<Align> = "-").
By default, the number is right-aligned.
<Sign>If this parameter is specified, displays a sign for positive numbers (<Sign> = "+"). This sign will appear to the left of the first significant digit.
By default, only negative numbers have a "-" sign to the left of the first significant digit.
Special case: if this parameter is specified and the number is equal to 0, the "+" sign will be displayed. This sign will also be displayed if a negative number becomes 0.
<Zero>If this parameter is specified (<Zero> ="0"), the number will be padded with leading zeros if the first significant part of the number is smaller that the specified length and the number is right-aligned.
By default, the number is not padded with leading zeros "0".
For example: NumToString(123, "05d") will return "00123".
<Length>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. The length must be less than 100.
If the specified length is too small to contain the significant part of the number, it will be ignored.
By default, the number will be the same length of the significant part (it cannot be padded with zeros). This is also the case if <Length> = 0.
If the specified length is greater than the significant part of the number:
  • the result string will be padded with trailing spaces if the number is left-aligned,
  • the result string will be padded with leading spaces or zeros if the number is right-aligned.
<.Precision>Defines the decimal separator ("." or ",") and the number of decimal places (for float ("f") and exponent ("e") <Types> only).
Decimal separator:
  • If the decimal separator is a comma, the decimal separator used will be the one defined:
    • in the linguistic parameters of Windows.
    • iPhone/iPadApple Watch for the current user.
  • If the decimal separator is a period, the decimal separator used will be a period.
Remarks:
  • ChangeSeparator has no effect on this separator. This function affects the display mask of numeric values in the controls.
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 decimal places in the number is less than <Precision>, the decimal part will be padded with trailing zeros "0".
  • The value of <Precision> can be greater than <Length>. In this case, <Length> is ignored.
<Type>Type of result, mandatory parameter:
  • d: Integer:
    A real number will be rounded to the nearest integer.
  • e: Exponential notation:
    If <Precision> is not specified, the default precision is 6.
  • f: Decimal notation:
    If <Precision> is not specified, the default precision is 6.
  • 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. Length not specified and negative number: 20 hexadecimal characters for a currency, 8 characters for all the other numeric types.
    2. Negative number: the length of the resulting string will be at least the length that allows the sign bit to be specified.
    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. Length not specified and negative number: 27 hexadecimal characters for a currency, 11 characters for all the other numeric types.
    2. Negative number: the length of the resulting string will be at least the length that allows the sign bit to be specified.
    For example: -32767 in the "3o" format will return "700001"
<Thousand>Thousands separator (<Thousand> = "S" or "s"). The digits in the integer part of the number will be grouped by 3 and separated by the thousands separator defined in Windows. The sign (if any) will always be displayed to the left of the first significant digit. There should be no thousands separators between the sign and the first digit.
iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile

Limitations

  • The "f" format returns a valid result for numbers between -1e+17 and 1e+17.
  • "x", "d" or "o" formats: the integer part must not exceed 99 999 999 999 999 999.
Versions 16 and later

Convert a size in bytes

To convert a size in bytes, use LengthToString.
New in version 16

Convert a size in bytes

To convert a size in bytes, use LengthToString.

Convert a size in bytes

To convert a size in bytes, use LengthToString.
Business / UI classification : Neutral code
Component : wd260std.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
Contador Regressivo
Global
gduTempoMaximo is Duration = 5min

---
Thread in Procedure
Infinito e inicio automaico em um segundo
---

gduTempoMaximo..Second -= 1

STC_TempoRestante = NumToString(gduTempoMaximo..Hour,"02d") + ":" + NumToString(gduTempoMaximo..Minute,"02d") + ":" + NumToString(gduTempoMaximo..Second,"02d")

----
Tempo Restante: 00:04:55

Bons estudos!
BOLLER
10 Sep. 2019
Video NumToString
https://youtu.be/3R67zX6ykP0

https://windevdesenvolvimento.blogspot.com/2019/05/dicas-2105-windev-webdev-mobile-dicas.html

sTexto+="HOSPEDAGEM: "+NumToString(EDT_HOSPEDAGEM_valor,"10,2f")+CR

// para numeros use "05d"

amarildo
18 May 2019
Exemplo de uso do NumToString
info(NumToString(1,"000002.00f")) = 000001

info(NumToString(1.20,"000002.00f")) = 000001.20
adrianoboller
06 Dec. 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
06 Dec. 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
06 Dec. 2016