Decimal numbers in Fields?

The Number Field does not seem to support decimal number when adding fields values etc?

The workaround I use:

// ******************************************************************************** 
// Function:       SumDecimalField                                                  
// Description:    Returns the value of two Fields added together                   
//                 Usage example:                                                   
//                 js:SumDecimalField(Edit3,Edit4)                                  
// Parameters:     field1 As Field,field2 As Field                                  
// Returns:        Decimal, returns 0 if any of the fields does not contain a valid 
//                  number                                                          
// ================================================================================ 
// Date       Version  Author               Description                             
// ---------- -------- -------------------- --------------------------------------- 
// 2018-11-30 1.0.0    Anders Forslund      Routine created                         
// ******************************************************************************** 
function SumDecimalField(field1,field2)
{
  // validate input
  if (isNumber(field1.Text) && isNumber(field2.Text))
    {
    return parseFloat(field1.Text,10) + parseFloat(field2.Text,10);
    }
  else
    {
    return 0;
    }  
}

// ******************************************************************************
// Routine:       isNumber
// Description:   Evaluates expression to check if it is numeric
// Parameters:    Expression
// Returns:       True/false
// ==============================================================================
// Date       Version  Author                         Description
// ---------- -------- ------------------------------ ---------------------------
// 2013-03-21 1.0.0    Anders Forslund                Routine created
// ******************************************************************************
function isNumber(n)
{
  return !isNaN(parseFloat(n)) && isFinite(n);
}

Leave a Comment