Я абсолютно не понимаю, что вы имеете в виду!

треть этот код:

function testprecision(){
    var isNotNumber = parseFloat('1.3').toPrecision(6);
    alert(typeof isNotNumber); //=> string
}

Я бы ожидал число. Если 'isNotNumber' должен быть действительным числом, решение проблемы заключается в преобразовании:

alert(typeof parseFloat(isNotNumber)) //=> number

[Редактировать] спасибо за ваши ответы. Точность не очень точный термин, который я заключаю. Это может представлятьобщее количество цифр числа иликоличество дробных цифр, Большинство людей в Нидерландах (откуда я родом) думают о точности в «количестве дробных цифр». Метод javascript toPrecision касается первого представления, поэтому это сбивает с толку. В любом случае, метод позволяет ввести «ложную точность», я прав? Для второго значения, которое мы должны исправить, то же самое относится и к этому (возвращает строку, возможность ложной точности).

Как бы то ни было, сделав изобретать велосипед своим главным хобби, я поиграл, чтобы создать объект с плавающей точкой javascript, используя полученные здесь знания. Может быть, это кому-то пригодится, или у кого-то из вас есть идеи получше?

function Float(f,nDec) {
  var Base = this,val;
  setPrecision( nDec || 2 );      
  set( f || 0, nDec || Base.precision );
  Base.set    = set;
  Base.ndec   = setPrecision;
  /** public setprecision 
   *  sets a value for the number of fractional
   *  digits (decimals) you would like getf to 
   *  return. NB: can't be more than 20.
   *  Returns the Float object, so allows method 
   *  chaining
   *  @param {Number} iPrecision
   */
  function setPrecision(iPrecision) {
      var ix = parseInt(iPrecision,10) || 2;
       Base.precision = ix >= 21 ? 20 : ix;
       return Base;
  }
  /** public set
   *  sets the 'internal' value of the object. Returns
   *  the Float object, so allows method chaining
   *  @param {Number} f
   *  @param {Number} ndec
   */
  function set(f,ndec) {
       val =  parseFloat(f) || 0;
       if (ndec) { setPrecision(ndec); }
       Base.val = val;
       return Base;
  }
  /** public get: 
   * return number value (as a float)
   */
  Base.get = function(){
      var ndec = Math.pow(10,Base.precision),
          ival = parseInt(val*ndec,10)/ndec;
      Base.val = ival;
      return Base.val;
  };
  /** public getf 
   *  returns formatted string with precision
   *  (see Base.setPrecision)
   *  if [hx] is supplied, it returns
   *  the float as hexadecimal, otherwise
   *  @param {Boolean} hx
   */
  Base.getf = function(hx){
      var v = Base.val.toFixed(Base.precision);
      return hx ? v.toString(16) : v;
  };
  /** public add
   * adds [f] to the current value (if [f] is a
   * Float, otherwise returns current value)
   * optionally sets a new number of decimals
   * from parameter [ndec]
   * @param {Number} f
   * @param {Number} ndec
   */
  Base.add = function(f,ndec){
      if ( parseFloat(f) || val===0) {
           set(Base.val+parseFloat(f));
           if (ndec) { setPrecision(ndec);}
      }
     return Base.get();
  };
  /** toString 
   *  returns the internal value of the Float object
   *  functions like a getter (supposedly)
   */
  Base.toString = Base.get;
}

Использование / пример:

var xf = new Float(); //=> value now 0.0
xf.set(0.86/0.8765,17).add(3.459);
alert(xf+'|'+xf.getf()); //=> 4.440175128351398|4.44017512835139800

Ответы на вопрос(1)

Ваш ответ на вопрос