5 ms·
displaying as a decimal is nondestructive, whereas doing math with a decimal is asking for trouble
by stronglikedan 5mo ago
displaying as a decimal is nondestructive, whereas doing math with a decimal is asking for trouble
- vitalikpie 5mo agoYeah this is exactly what I do under the hood. All the data is stored as Ints, charts use double for speed, views use decimal to display stuff properly in the user locale. P.S. Doubles are absolute evil for calculations: @Test func test() { var a = Decimal(100.4449315513924) * 100 // It's me being dumb, not noticing that let b = NSDecimalNumber(decimal: a).intValue #expect(b == 10044) // Expectation failed: (b → -8402) == 1044 }
- hakfoo 5mo agoBecause decimal types are still vanishingly scarce as a built-in in modern languages. Storage as an integer often adds complexity because of currency reforms. Decimals can and have been dropped in the past.