GUVI
Back

To fix decimals without round off

Created 2 years ago
121 Views
4 Comments
vigneshwarRV
@vigneshwarRV
vigneshwarRV
@vigneshwarRVProfile is locked. Login

please explain is there a way to fix decimals to certain digits without round off..

Given length L and breadth B of a farm, print the area of the farm upto 5 decimal decimals.
Sample Testcase :
INPUT
1.626 2.31
OUTPUT
3.75606

ANSWER:

// Getting input via STDIN

const readline = require("readline");

const inp = readline.createInterface({

input: process.stdin

});

const userInput = [];

inp.on("line", (data) => {

userInput.push(data);

});

inp.on("close", () => {

//start-here

//Your code goes here … replace the below line with your code logic

let a = userInput[0].split(' ').map(a=>+a);

let area = (a[0]*a[1]).toFixed(5);

console.log(area);

//end-here

});

the problem is when I try to fix decimal to 5 digits , the last digit round off to 7 and I  dont know how to fix that.

The problem is when I fix decimal to 5 digits , the last digit round off to 7 and I don't know how to avoid that

Comments (4)
Please login to comment.
 
Powered by habitate.io Habitate