|
@@ -1,7 +1,7 @@
|
|
|
import React, {useState, useEffect, useRef} from "react";
|
|
|
import DataGrid, {Column} from "devextreme-react/data-grid";
|
|
|
import {Alert} from "./AlertDialog.js";
|
|
|
-import {addNumbersToGrid, numbersToArrOfArr} from "./helpers.js";
|
|
|
+import {addNumbersToGrid, numbersToArrOfArr, afterCommaLen} from "./helpers.js";
|
|
|
import "./App.css";
|
|
|
|
|
|
let imdtRes;
|
|
@@ -12,7 +12,7 @@ let noOfDigits = 0;
|
|
|
function Subtraction() {
|
|
|
const [input, setInput] = useState(""); // initial user input like 34+56.7
|
|
|
const [realResult, setRealResult] = useState(0); // real result of calculation
|
|
|
- const [carryArr, setCarryArr] = useState([]); // array of carries [1","0"]
|
|
|
+ const [carryArr, setCarryArr] = useState([]); // array of carries ["1","0"]
|
|
|
const [commaIdx, setCommaIdx] = useState(0); // int: comma position
|
|
|
const [numbers, setNumbers] = useState(0); // array of arrays with input numbers
|
|
|
const [showAlert, setShowAlert] = useState(false);
|
|
@@ -72,6 +72,9 @@ function Subtraction() {
|
|
|
for (let i=1; i<numbers.length; i++){
|
|
|
realRes -= numbers[i]
|
|
|
}
|
|
|
+
|
|
|
+ let afterComma = Math.max(...numbers.map(x => afterCommaLen(x)));
|
|
|
+ realRes = parseFloat(realRes.toFixed(afterComma));
|
|
|
setRealResult(realRes);
|
|
|
|
|
|
let [numbersArr, commaIdx] = numbersToArrOfArr(numbers);
|