r/Scriptable • u/picachu11 • May 10 '22
Solved How to change decimal places in result
I get a result as 2.64136464. How to get a result as 2.64. What code to use?
3
Upvotes
r/Scriptable • u/picachu11 • May 10 '22
I get a result as 2.64136464. How to get a result as 2.64. What code to use?
11
u/[deleted] May 10 '22
var.toFixed(2);
1
u/picachu11 May 10 '22
Thanks for the answers. I am a beginner and not sure what exactly should I add here to see a number like 2.64. I tried var.tofixed and a function but it throws me an error. let unpaidTxt = w.addText(unpaid ) unpaidTxt.textColor = Color.orange() unpaidTxt.font = Font.systemFont(16) unpaidTxt.centerAlignText()
2
u/Bright-Historian-216 May 10 '22
After quick experiments, i found Math.round(). I still don't know if it works because another part of the code I tried to write to test it returns an error, but try that function. Edit: it works but just converts float to number so try Math.round(your_number*100)/100
2
u/iamrbn script/widget helper May 10 '22 edited May 10 '22
Maybe this will helps you.
I’ve written an script that includes parts of this link. Here is the snippet about it:
output:
Maybe you will get the right result if you play with the parameters
('en-US' {notation:'compact', maximumSignificantDigits: 4})