I have a question about JS math. So I'm trying to make 71.602
to look like 71(60%)
but I don't really know how to do it.
This should work
const a = 71.602
const s = a.toFixed(2).toString().split('.')
console.log(`${s[0]}(${s[1]}%)`)
Output
71(60%)
Try this. very simple way.
var str = "71.602";
var res = str.split(".");
var dec = res[1];
console.log(res[0] + '(' + parseInt(dec/10) + '%)');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.