Official Content

Converts a number in character format to numeric format.

Syntax

String.ToNumeric()

Where:

String
  
 Is an attribute or variable based on the Character/VarChar/LongVarChar data type.
  

Type Returned:
Numeric N(18.2)

Scope

Data Types: Character, VarChar, LongVarChar
Generators: .NET, .NET Framework, Java, Ruby (up to GeneXus X Evolution 3), Visual FoxPro (up to GeneXus X Evolution 3)

Description

This method converts the numbers of a character expression to a numeric type. It processes the numbers in the character expression from left to right until a non-numeric character is encountered. If the first character of the character expression is not a number, the result of ToNumeric method will be 0.

Samples

&AcceptTxt = '-123.35'
&Nbr = &AcceptTxt.ToNumeric() //&Nbr = -123

&AcceptTxt = 'ABC'(*)
&Nbr = &AcceptTxt.ToNumeric() //&Nbr = 0

&AcceptTxt = '12A' (*)
&Nbr = &AcceptTxt.ToNumeric() //&Nbr = 12 

Note: Converting alphanumerics to numerics (*) is not supported when the method is evaluated in the DBMS (see Server Side Functions/Methods or SAC 42709).

See Also

Val function
Str function
ToString method

   


Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant