Это видео недоступно.
Сожалеем об этом.

JavaScript Tip: Avoiding Problems with Decimal Math

Поделиться
HTML-код
  • Опубликовано: 14 авг 2024
  • Though not an exciting topic, dealing with decimal math in javascript is an important topic. Because of the way JavaScript stores numbers, it may provide inaccurate results when doing math on decimals. In this tutorial I will show you to solutions.
    Would you like to help keep this channel going?
    / allthingsjavascript
    For more resources on JavaScript:
    www.allthingsja...
    Courses offered on Udemy: Getting Started or Advanced Topics at a huge discount:
    www.udemy.com/...
    www.udemy.com/...
    New Mastering Regular Expressions in JavaScript:
    www.udemy.com/...
    Tutorials referred to in this video:
    JavaScript Objects Playlist: • JavaScript Objects
    #javascript #AllThingsJavaScriptLLC

Комментарии • 29

  • @carlosfernandez6470
    @carlosfernandez6470 5 лет назад +2

    Wow Sir , please never stop doing this vídeos. I love to learn something new every time

  • @daegudude1048
    @daegudude1048 4 года назад +2

    Thank you sir! It's very slow paced so it helps me understand better!

  • @dkcaliskan
    @dkcaliskan 3 года назад +1

    Really thank you sir! I was going to get crazy with numbers

  • @RameenFallschirmjager
    @RameenFallschirmjager 4 года назад

    With voice of yours, everything you say I believe!

  • @marczwiers5876
    @marczwiers5876 5 лет назад +1

    I love your videos!! Thank you so much always for this amazing video!

  • @KosalaSubasinghe1
    @KosalaSubasinghe1 2 года назад +1

    Awesome tutorial!!
    How about new Big(3).div(new Big(10.2)).times(new Big(10.2)) ? it suppose to give new 3 but gives less than or greater than 2 depends on DP , RM configuration.

    • @milestailsprower4555
      @milestailsprower4555 Год назад

      Rounding mode ==== 2 (ROUND_CEIL)
      This always rounds up unless it's infinite string of zeros

  • @rickvian
    @rickvian 3 года назад +1

    i got this question during interview in reputable logistic chain company

  • @baezaomarrene1
    @baezaomarrene1 4 года назад

    Very Helpful Thank you very much!

  • @abdimussa8932
    @abdimussa8932 Год назад

    Thank you sir for the educative video. Can't we just use .toFixed(2) to get the correct result instead of using a library? For example, (0.1+0.2).toFixed(2) gives us 0.30

    • @AllThingsJavaScript
      @AllThingsJavaScript  Год назад

      That would work for that specific situation. This is just an example of issues you could run into.

    • @abdimussa8932
      @abdimussa8932 Год назад

      @@AllThingsJavaScript On which scenario wouldn't it work?

    • @AllThingsJavaScript
      @AllThingsJavaScript  Год назад +1

      @@abdimussa8932 Here is a pretty good article that goes into more detail: www.progress.com/blogs/limitations-number-type-javascript

  • @rodrigochaclan8349
    @rodrigochaclan8349 2 года назад

    Really thanks

  • @hemaldon
    @hemaldon 3 года назад

    Thanks

  • @RameenFallschirmjager
    @RameenFallschirmjager 4 года назад +1

    Javascript is drunk! It needs to sniff some cocaine to sober up!

  • @ronjobs2359
    @ronjobs2359 5 лет назад

    Could you please suggest some libraries for Dates? because i find Dates frustrating in javascript

    • @AllThingsJavaScript
      @AllThingsJavaScript  5 лет назад

      Here are a few tutorials I've done on dates: ruclips.net/video/j8katkbMVhs/видео.html and ruclips.net/video/uWQEGgNvac0/видео.html I haven't used a library for dates, but did a quick look and this one looks pretty decent: momentjs.com/

  • @seenuvasanv
    @seenuvasanv 5 лет назад

    love this videos, waiting for nodeJs.

    • @AllThingsJavaScript
      @AllThingsJavaScript  5 лет назад +1

      Here is the playlist with the current tutorials I've done on node. ruclips.net/p/PLTo9PCskHpbHOCWbxxukNU8sp57tPy4Qh

    • @seenuvasanv
      @seenuvasanv 5 лет назад

      @@AllThingsJavaScript Thanks for your reply. I done all these.

    • @AllThingsJavaScript
      @AllThingsJavaScript  5 лет назад +1

      @@seenuvasanv Sounds good. I have more planned, but the vanilla javascript is most popular, so I've focused on those.

  • @hamidrezakazemi7746
    @hamidrezakazemi7746 5 лет назад

    thanks,👍 good topic, speed up plz.

    • @RameenFallschirmjager
      @RameenFallschirmjager 4 года назад

      حمیدرضا خان، این یه ویدئو آموزش برنامه نویسیه، مسابقه فوتبال نیستش که سرعت لازم داشته باشه! برای یادگیری باید صبور بود، و حوصله ای که ایشون از خودش نشون میده بسیار خوب و قابل ستایسشه، و بیننده هم باید شکیبا باشه تا چیز یاد بگیره

  • @davidramentol4877
    @davidramentol4877 2 года назад

    80.1 * 100 = 8009.999999999999

    • @milestailsprower4555
      @milestailsprower4555 2 года назад

      Using Dec.mul(Dec('80.10'),Dec('100')) from decimal.js returns 8,010
      First input: Dec = Decimal.clone({precision:5,toExpPos:+10,toExpNeg:-5,rounding:8}) Dec.divide(Dec('1E+13'),Dec('32')).toString(), Returned output: '3.12e+13'
      Second input: Dec = Decimal.clone({precision:5,toExpPos:+10,toExpNeg:-5,rounding:8})
      Dec.divide(Dec('-1E+13'),Dec('32')).toString(), Returned output: '-3.13e+13'

  • @amyr4ikgirl132
    @amyr4ikgirl132 2 года назад

    Thank you sir! It's very slow paced so it helps me understand better!