Parse a String to a Number

The following sample parses a string (formatted according to the user’s preference) to a raw number value, using format.parse(options).

Note:

This sample script uses the require function so that you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.

          /**
 * @NApiVersion 2.x
 */

require(['N/format'], 
    function(format){
         function parseToValue() {
              // Assume number format is 1.000.000,00 and negative format is -100
              var formattedNum = "-20.000,25"
              return format.parse({value:formattedNum, type: format.Type.FLOAT})
              }
         var rawNum = parseToValue(); // -20000.25 -- a number 
   }); 

        

General Notices