2 ms·
Yeah, I'm pretty sure he'll turn up his nose at that solution as well. For purposes of teaching the language to a beginner, he wants literals being rounded or
by webmaven 10y ago
Yeah, I'm pretty sure he'll turn up his nose at that solution as well.
For purposes of teaching the language to a beginner, he wants literals being rounded or divided to "just work" in a way that is unsurprising to those beginners, and there isn't any way to achieve that unless the default type of a number with a decimal point is Decimal rather than float (which isn't at all likely to happen).
The closest we are likely to get to that ideal is by introducing a Decimal literal like 0d2.125, riffing off the Hex and Octal literals (eg. 0xDEADB33F, 0o76510).
P.S., unless I am mistaken, you're just truncating the float, not actually rounding it