<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>A Pen by 擬音の妖精さん of neko</title>
</head>
<body>
getStorageResult1
getStorageResult1
<script src="js/index.js"></script>
</body>
</html>
/*Downloaded from https://www.codeseek.co/neko_sugar310gb/a-pen-by-andx64ecandx97f3andx306eandx5996andx7cbeandx3055andx3093-of-neko-mLNjpo */
function getDotPosition(value){
// 数値のままだと操作できないので文字列化する
var strVal = String(value);
var dotPosition = 0;
// 小数点が存在するか確認
if(strVal.lastIndexOf('.') !== -1){
// 小数点があったら位置を取得
dotPosition = (strVal.length-1) - strVal.lastIndexOf('.');
}
return dotPosition;
}
function calcSubtract(value1,value2){
// それぞれの小数点の位置を取得
var dotPosition1 = getDotPosition(value1);
var dotPosition2 = getDotPosition(value2);
// 位置の値が大きい方(小数点以下の位が多い方)の位置を取得
var max = Math.max(dotPosition1,dotPosition2);
// 大きい方に小数の桁を合わせて文字列化、
// 小数点を除いて整数の値にする
var intValue1 = parseInt((value1.toFixed(max) + '').replace('.', ''));
var intValue2 = parseInt((value2.toFixed(max) + '').replace('.', ''));
// 10^N の値を計算
//var power = Math.pow(10,max);
// 整数値で引き算した後に10^Nで割る
return (intValue1/intValue2) /// power;
}
var val1 = 10008;
var val2 = 1.08;
var result = calcSubtract(val1,val2);
console.log("解:"+result);