Changeset 6248


Ignore:
Timestamp:
Feb 26, 2013, 10:50:19 AM (9 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1744: The Number.formatNumber() function in main.js is not correct in all cases

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2-stable/www/include/scripts/main.js

    r6148 r6248  
    16151615  this.formatNumber = function(value, numDecimals, unit)
    16161616  {
    1617     if (!value) return '';
     1617    if (typeof value != 'number') return '';
    16181618    var result = '';
    1619     if (value < 0)
    1620     {
    1621       result += "-";
    1622       value = -value;
    1623     }
    16241619    if (numDecimals < 0)
    16251620    {
    1626       result += value;
    1627     }
    1628     else if (numDecimals == 0)
    1629     {
    1630       result += Math.round(value);
     1621      result = value;
    16311622    }
    16321623    else
    16331624    {
    1634       var intPart = Math.floor(value);
    1635       var decimals = Math.round((value - intPart) * Math.pow(10, numDecimals));
    1636       result += intPart + '.' + decimals;
     1625      result = value.toFixed(numDecimals);
    16371626    }
    16381627    if (unit) result += unit;
Note: See TracChangeset for help on using the changeset viewer.