3 ms·
Yep, I'd be curious what any better alternative is. Consider that a float's internal representation is in base 2, and you're trying to round in base 10. Even i
by dheera 7y ago
Yep, I'd be curious what any better alternative is.
Consider that a float's internal representation is in base 2, and you're trying to round in base 10. Even if you didn't use a string, I'd assume you'd have to create an array of ints that contain base 10 digits in order to do the rounding, unless there are some weird math tricks that can be employed that can avoid you having to process all base 2 digits. And an array of ints isn't all that computationally different from a string.
- masklinn 7y agoIn fact, I don't know what cdecimal now does but back when decimal.Decimal was pure python it would store the "decimal number" as a string and manipulate that.