Beehaw
  • Communities
  • Create Post
  • search
    Search
  • Login
  • Sign Up
Inductor ( Inductor@feddit.de )  to Programmer Humor@programming.dev · 3 years ago

0.30000000000000004

feddit.de

message-square
30
link
fedilink
284

0.30000000000000004

feddit.de

Inductor ( Inductor@feddit.de )  to Programmer Humor@programming.dev · 3 years ago
message-square
30
link
fedilink
  • psud ( psud@aussie.zone ) 
    link
    fedilink
    arrow-up
    32
    ·
    3 years ago

    If working in currency, work in cents and divide by 100 and round to 2 decimals for output

    • IWantToFuckSpez ( IWantToFuckSpez@kbin.social ) 
      link
      fedilink
      arrow-up
      38
      ·
      3 years ago

      Yeah round down and transfer the remainder to an account you own.

      • psud ( psud@aussie.zone ) 
        link
        fedilink
        arrow-up
        6
        ·
        3 years ago

        Indeed, Lex

    • janAkali ( janAkali@lemmy.one ) 
      link
      fedilink
      English
      arrow-up
      13
      ·
      3 years ago

      Most languages have decimal libraries to correctly handle floating point arithmetics, where precision is necessary.

      • Slotos ( Slotos@feddit.nl ) 
        link
        fedilink
        arrow-up
        1
        ·
        3 years ago

        They are as incapable of handling one third of a dollar as binary positional notation is incapable of handling one fifth (0.2).

        It’s not really a float problem. It’s a positional notation one. Some perfectly rational numbers refuse to squeeze into that mold.

        • szczuroarturo ( szczuroarturo@programming.dev ) 
          link
          fedilink
          arrow-up
          1
          ·
          3 years ago

          Also decimal system is not exatcly that much better since you also cant write 1/3 in decimal

    • MJBrune ( MJBrune@beehaw.org ) 
      link
      fedilink
      English
      arrow-up
      9
      ·
      edit-2
      3 years ago

      deleted by creator

      • CanadaPlus ( CanadaPlus@lemmy.sdf.org ) 
        link
        fedilink
        arrow-up
        11
        ·
        3 years ago

        You’re telling me there’s someone that has more than 20 million dollars? /s

        If you’re handling people’s money you should probably be using arbitrary-precision arithmetic. I mean, you might get away with a long int, but finance is serious business and the amount of data you’re going to be processing relative to your funding is probably going to be small.

        • psud ( psud@aussie.zone ) 
          link
          fedilink
          arrow-up
          1
          ·
          3 years ago

          Not the project I was thinking about above, but at work my team delivered software handling 13 digit numbers, but that’s in COBOL which does fine with money

    • Jajcus ( Jajcus@kbin.social ) 
      link
      fedilink
      arrow-up
      9
      ·
      3 years ago

      If working with currency use types and formating functions appropriate for currency. Not float.

      • psud ( psud@aussie.zone ) 
        link
        fedilink
        arrow-up
        2
        ·
        3 years ago

        I was recalling a project in perl, which doesn’t have a variety of types. If you add values, you get a scalar, which will be a float if the numbers are not integers.

        I am aware my statement isn’t true in several languages

    • Buckshot ( Buckshot@programming.dev ) 
      link
      fedilink
      arrow-up
      7
      ·
      3 years ago

      And remember not all currencies are 2dp so get a list and use the appropriate exponent.

      I had to update our currency database this week because there’s new currencies. It’s almost as bad as timezones.

      • ruk_n_rul ( ruk_n_rul@monyet.cc ) 
        link
        fedilink
        arrow-up
        1
        ·
        3 years ago

        Buckshot@programming.dev wake up, new currencies just dropped

    • redcalcium ( redcalcium@lemmy.institute ) 
      link
      fedilink
      arrow-up
      2
      ·
      3 years ago

      Some programming languages use different rounding method. Might bite you in the ass if you’re not aware of it and using multiple programming language in your application to handle different areas.

    • Zikeji ( Zikeji@programming.dev ) 
      link
      fedilink
      English
      arrow-up
      2
      ·
      3 years ago

      That’s what I wound up doing on a work project. Works really well.

Programmer Humor@programming.dev

programmer_humor@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmer_humor@programming.dev

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics
    • If the mod doesn’t find it funny, you’re banned. Ha-ha!.. For real: do not use the community for “statements”. There are other places for such content. Keep it chill and funny.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 1.02K users / day
  • 2.37K users / week
  • 3.67K users / month
  • 7.54K users / 6 months
  • 463 local subscribers
  • 33.6K subscribers
  • 1.55K Posts
  • 25.4K Comments
  • Modlog
  • mods:
  • Feyter ( Feyter@programming.dev ) 
  • adr1an ( anzo@programming.dev ) 
  • BurningTurtle ( BurningTurtle@programming.dev ) 
  • Pierre-Yves Lapersonne ( pylapp@programming.dev ) 
  • BE: 0.19.15
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code