It depends on the requirements of your app and what programming language you use. Sometimes you can get away with using a fixed precision that you can assume everywhere, but most common programming languages will have some implementation of a decimal type with variable precision if needed, so you won’t need to implement it on your own outside of university exercises.
Comment on IEEE 754
Saleh@feddit.org 2 weeks agoSo if you handle different precisions you also need to store the precision/exponent explicitly for every value. Or would you sanitise this at input and throw an exception if someone wants more precision than the program is made for?
jmcs@discuss.tchncs.de 2 weeks ago
Saleh@feddit.org 2 weeks ago
Okay thank you. I was wondering because for stuff like buying electricity, gas or certain resources, parts etc. there is prices with higher precision in cents, but the precision would not be identical over all use cases in a large company.
wewbull@feddit.uk 2 weeks ago
No exponent, or at least a common fixed exponent. The technique is called “fixed point” as opposed to “floating point”. The rationale is always to have a known level of precision.