truncateAsFixed() idea #56039
Labels
area-core-library
SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
triage-automation
Issues triaged by automation (see https://github.com/dart-lang/sdk/wiki/Triage-automation)
type-enhancement
A request for a change that isn't a bug
Hello, I ran into an issue today at work (using flutter at work) where I was receiving a double from the backend that was
116.41666666
. I wanted to display this value as an amount of money, such as£116.41
and I didn't expect any rounding to occur.Unfortunately, I found out that
toStringAsFixed()
does appear to round as I was getting£116.42
on the display. I searched but I didn't see any kind of way to effectively truncate a double to a fixed amount.In the end, I created a function to do it for me. I don't think it's great but maybe a jumping-off point for a feature that I think would be useful to have in the SDK.
https://dartpad.dev/?id=e8ab76b086cbd79b212491b38bf58a7f
Only now of writing this do I see on the docs the example line
toStringAsFixed()
where it shows rounding but my personal opinion is that it's not obvious enough. Perhaps instead
maybe it's the 1, 2, 3, ... it doesn't stand out.
Either way, kind regards, Tom.
The text was updated successfully, but these errors were encountered: