Javascript浮動小数点数は正確に計算されます.


浮動小数点計算の精度の問題はjavascript自身にある問題です.
比較経典の例は2.0-1.1で、計算結果は0.899999999999です.
正確な計算の基本的な考え方は、すべてを整数に変換して計算し、整数計算には誤差が存在しない.
以下のコード1はテストです.添付ファイルをダウンロードすることもできます.添付ファイルにすでに含まれています.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>         </title>
		<script type="text/javascript" src="js/FloatCumulateV1.js"></script>
		<script type="text/javascript">
		    window.onload = function(){
		    	document.getElementById("1").innerHTML = (0.01/0.1) ;
		    	document.getElementById("2").innerHTML = (Number(0.01).div(Number(0.1))) ;
		    	
		    	document.getElementById("3").innerHTML = (1.5*0.1) ;
		    	document.getElementById("4").innerHTML = (Number(1.5).mul(Number(0.1))) ;
		    	
		    	document.getElementById("5").innerHTML = (0.09999999+0.00000001) ;
		    	document.getElementById("6").innerHTML = (Number(0.09999999).add(Number(0.00000001))) ;
		    	
		    	document.getElementById("7").innerHTML = (2.0-1.1) ;
		    	document.getElementById("8").innerHTML = (Number(2.0).sub(Number(1.1))) ;
		    	
		    	document.getElementById("9").innerHTML = (Number(10).div(Number(0.1))) ;
		    	document.getElementById("10").innerHTML = (Number(10).mul(Number(0.1))) ;
		    	document.getElementById("11").innerHTML = (Number(10).add(Number(0.2))) ;
		    	document.getElementById("12").innerHTML = (Number(10).sub(Number(1.1))) ;
		    	
		    }
			
		</script>
	</head>
	<body>
		<h1>         </h1>
		<p>  js    : 0.01/0.1 = <label id="1"> </label></p>
		<p>  js    : 0.01/0.1 = <label id="2"> </label></p>
		
		<p>  js    : 1.5*0.1 = <label id="3"> </label></p>
		<p>  js    : 1.5*0.1 = <label id="4"> </label></p>
		
		<p>  js    : 0.09999999+0.00000001 = <label id="5"> </label></p>
		<p>  js    : 0.09999999+0.00000001 = <label id="6"> </label></p>
		
		<p>  js    : 2.0-1.1 = <label id="7"> </label></p>
		<p>  js    : 2.0-1.1 = <label id="8"> </label></p>
		

		<p>  js    (    ,  Exception   ): 10/0.1 = <label id="9"> </label></p>		
		<p>  js    (    ,  Exception   ): 10*0.1 = <label id="10"> </label></p>	
		<p>  js    (    ,  Exception   ): 10+0.2 = <label id="11"> </label></p>		
		<p>  js    (    ,  Exception   ): 10-1.1= <label id="12"> </label></p>
	</body>
</html>

これは実行結果:
         

  js    : 0.01/0.1 = 0.09999999999999999

  js    : 0.01/0.1 = 0.1

  js    : 1.5*0.1 = 0.15000000000000002

  js    : 1.5*0.1 = 0.15

  js    : 0.09999999+0.00000001 = 0.09999999999999999

  js    : 0.09999999+0.00000001 = 0.1

  js    : 2.0-1.1 = 0.8999999999999999

  js    : 2.0-1.1 = 0.9

  js    (    ,  Exception   ): 10/0.1 = 100

  js    (    ,  Exception   ): 10*0.1 = 1

  js    (    ,  Exception   ): 10+0.2 = 10.2

  js    (    ,  Exception   ): 10-1.1= 8.9
function accDiv(arg1, arg2)
{
	var tmp1 = 0;
	var tmp2 = 0;
	var result1 = 0;
	var result2 = 0;

    //                 。
	try 
	{
		tmp1 = arg1.toString().split(".")[1].length;
	} 
	catch(e) 
	{
		tmp1 = 0;
	}

	try 
	{
		tmp2 = arg2.toString().split(".")[1].length;
	} 
	catch(e) 
	{
		tmp2 = 0;
	}

	result1 = Number(arg1.toString().replace(".", ""));
	result2 = Number(arg2.toString().replace(".", ""));
	
	return (result1 / result2) * Math.pow(10, tmp2 - tmp1);
}

Number.prototype.div = function(arg) {
	return accDiv(this, arg);
}

function accMul(arg1, arg2) 
{
	var tmp1 = 0;
	var tmp2 = 0;
	var result1 = 0;
	var result2 = 0;
	
	try 
	{
		tmp1 = arg1.toString().split(".")[1].length;
	} 
	catch (e) 
	{
        tmp1 = 0;
	}

	try 
	{
		tmp2 = arg2.toString().split(".")[1].length;
	} 
	catch (e) 
	{
		tmp2 = 0;
	}

	result1 = Number(arg1.toString().replace(".", ""));
	result2 = Number(arg2.toString().replace(".", ""));

	return (result1 * result2) / Math.pow(10, tmp1 + tmp2);
}

Number.prototype.mul = function(arg) {
	return accMul(this, arg);
}

function accAdd(arg1, arg2) 
{
	var tmp1 = 0;
	var tmp2 = 0;
	var tmp = 0;
	var result1 = 0;
	var result2 = 0;
	try 
	{
		tmp1 = arg1.toString().split(".")[1].length;
	} 
	catch (e) 
	{
		tmp1 = 0;
	}

	try 
	{
		tmp2 = arg2.toString().split(".")[1].length;
	} 
	catch (e) 
	{
		tmp2 = 0;
	}
	
	//arg1 + arg2 = ( result1/Math.pow(10,tmp1) ) + ( result2/Math.pow(10,tmp2) )
	//1.5+0.02 = 15/10 + 2/100
	//1.5+0.02 = 1.5*100/100 + 2*100/100
	tmp = Math.max(tmp1, tmp2);
	return (arg1 * Math.pow(10, tmp) + arg2 * Math.pow(10, tmp)) / Math.pow(10, tmp);

}

Number.prototype.add = function(arg) {
	return accAdd(this, arg);
}

//              。
function accSub(arg1, arg2) 
{
	var tmp1 = 0;
	var tmp2 = 0;
	var tmp = 0;
	var result1 = 0;
	var result2 = 0;
	
	try 
	{
		tmp1 = arg1.toString().split(".")[1].length;
	} 
	catch (e) 
	{
		tmp1 = 0;
	}

	try 
	{
		tmp2 = arg2.toString().split(".")[1].length;
	} 
	catch (e) 
	{
		tmp2 = 0;
	}

	tmp = Math.max(tmp1, tmp2);
	return (arg1 * Math.pow(10, tmp) - arg2 * Math.pow(10, tmp)) / Math.pow(10, tmp);
}

Number.prototype.sub = function(arg) {
	return accSub(this, arg);
}