this post was submitted on 02 Jan 2025
432 points (98.4% liked)

Science Memes

14853 readers
1826 users here now

Welcome to c/science_memes @ Mander.xyz!

A place for majestic STEMLORD peacocking, as well as memes about the realities of working in a lab.



Rules

  1. Don't throw mud. Behave like an intellectual and remember the human.
  2. Keep it rooted (on topic).
  3. No spam.
  4. Infographics welcome, get schooled.

This is a science community. We use the Dawkins definition of meme.



Research Committee

Other Mander Communities

Science and Research

Biology and Life Sciences

Physical Sciences

Humanities and Social Sciences

Practical and Applied Sciences

Memes

Miscellaneous

founded 2 years ago
MODERATORS
 

cross-posted from: https://lemmy.ml/post/24332731

~~Stolen~~ Cross-posted from here: https://fosstodon.org/@foo/113731569632505985

you are viewing a single comment's thread
view the rest of the comments
[–] tdawg@lemmy.world 16 points 5 months ago (4 children)

Please tell me you aren't using floating points with money

[–] wewbull@feddit.uk 36 points 5 months ago

Knowing not to use floating point with money is good use of that knowledge.

[–] psivchaz@reddthat.com 5 points 5 months ago

You'd be dismayed to find out how often I've seen people do that.

[–] zqwzzle@lemmy.ca 3 points 5 months ago (1 children)

Yeah I shudder when I see floats and currency.

[–] Womble@lemmy.world 3 points 5 months ago* (last edited 5 months ago)

Eh, if you use doubles and you add 0.000314 (just over 0.03 cents) to ten billion dollars you have an error of 1/10000 of a cent, and thats a deliberately perverse transaction. Its not ideal but its not the waiting disaster that using single precision is.

[–] Saleh@feddit.org 2 points 5 months ago (1 children)

How do you do money? Especially with stuff like some prices having three or four decimals

[–] jmcs@discuss.tchncs.de 10 points 5 months ago (1 children)

Instead of representing $1.102 as 1.102 your store it as 1012 (or whatever precision you need) and divide by 1000 only for displaying it.

[–] Saleh@feddit.org 1 points 5 months ago (2 children)

So 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 6 points 5 months ago (1 children)

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.

[–] Saleh@feddit.org 2 points 5 months 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 5 points 5 months 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.