decimal icon indicating copy to clipboard operation
decimal copied to clipboard

How to force decimals?

Open liuaiyuan opened this issue 4 years ago • 1 comments

 NewFromFloat(5.45600).Round(4).String() // output: "5.4560"

// I want output in the following format
 NewFromFloat(5).Round(4).String() // output: "5.0000"

liuaiyuan avatar Jun 06 '21 03:06 liuaiyuan

Hi! Currently, the are two ways to achieve that. Both are not the most elegant, but they work :D

NewFromFloat(5.45600).Truncate(0).Round(4).String()   // output: "5.0000"
NewFromFloat(5.45600).Round(0).Round(4).String()      // output: "5.0000"

Hopefully, I understood your question correctly. If no, please let me know. :D

mwoss avatar Jun 07 '21 23:06 mwoss