Hacker News new | past | comments | ask | show | jobs | submit login

Would it be better to store the integer and fractional parts separately, or mantissa and exponent?



I’m just going to say “no”.

If you don’t need to work with the value, store it in a string. If you do, use a proper decimal type. (Your question may then apply to the internals of the decimal type, but the point is that that should be transparent to the developer accessing the decimal value.)


Most developers don't know the difference between a float and a decimal. I've had to fix this at least five times in my career.


My favorite is when someone tries to treat either a Zipcode or a CVV as a number.


I think that makes sense, given the room for confusion

Just curious does any country use fractions of a bill other then 1/100 (ie cents)


This was posted here regarding some similar discussion a while ago.

"Falsehoods programmers believe about prices"

https://gist.github.com/rgs/6509585


The USA does, for example. There are ten mill in a cent. Apparently Tunisia even has five-mill coins in circulation.

https://en.wikipedia.org/wiki/Mill_(currency)


Going to add to the other comments that the "1" is not a bill in many currencies. For example the smallest Euro bill is 5€.

Other currencies do not have a fractional part at all and use just one integer.


FWIW Japan doesn’t use fractions - 1 yen is approx 1 US penny. Lunch is 300-500 yen.


IIRC correctly one country uses three digits in the less than one realm. This site https://www.localeplanet.com/icu/currency.html has one three and even a four.


US gas stations frequently give prices in fractions of a cent.

https://www.marketplace.org/2018/10/11/why-do-gas-prices-end...


Meh, from what I've seen so far, it's just so people see, e.g. 2.55 $/gal with the tiny nine in the corner, stop by and get charged 2.559 $/gal (essentially squeezing that last cent out of customers.)

I'd be interested to hear if anyone else has seen any digit other than nine in the tenth-of-a-cent column though.


I believe it's because gas prices are quoted with tax (which is unusual in the US), and there is a federal tax ending in 9 tenths of a cent. Probably lobbied by the small 9 marquee digit manufacturers of america.


Australian fuel prices are listed in cents to one decimal place. >80% of the time the last digit is a nine, the rest of the time it’s most commonly a 5. I’ve seen other odd digits rarely, with even numbers just about unheard of. But what you actually pay will be rounded to the cent, or to the nearest 5¢ if you pay in cash.

The whole concept involved here is called psychological pricing (https://en.wikipedia.org/wiki/Psychological_pricing). I wish it was illegal.


Yes 1/1000 is very commom in the Arab world.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: