PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • 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.
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.
<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>]"


    See remarks for more details.
  • Versions 17 and later
    iPhone/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
    iPhone/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.
    iPhone/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>]"
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.
<.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.
    • 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.
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.
<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.
iPhone/iPadWindows MobileUniversal Windows 10 App

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.

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.
Component : wd240std.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
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