Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6563415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:51:01+00:00 2026-05-25T13:51:01+00:00

When I pull the values I want to multiply, they’re strings. So I pull

  • 0

When I pull the values I want to multiply, they’re strings. So I pull them, parse them as floats (to preserve the decimal places), and multiply them together.

LineTaxRate = parseFloat(myRate) * parseFloat(myQuantity) * parseFloat(myTaxRateRound);

This has worked for 99% of my invoices but I discovered one very odd problem.

When it multiplied: 78 * 7 * 0.0725

Javascript is returning: 39.584999999999994

When you normally do the math in a calculator its: 39.585

When all is said and done, I take that number and round it using .toFixed(2)

Because Javascript is returning that number, it’s not rounding to the desired value of: $39.59

I tried Math.round() the total but I still get the same number.

I have thought of rounding the number to 3 decimals then two, but that seems hacky to me.

I have searched everywhere and all I see is people mention parseFloat loses its precision, and to use .toFixed, however in the example above, that doesn’t help.

Here is my test script i made to recreate the issue:

<script>
var num1 = parseFloat("78");
var num2 = parseFloat("7");
var num3 = parseFloat("0.0725");
var myTotal = num1 * num2 * num3;
var result = Math.round(myTotal*100)/100

alert(myTotal);
alert(myTotal.toFixed(2));
alert(result);
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:51:02+00:00Added an answer on May 25, 2026 at 1:51 pm

    Floating points are represented in binary, not decimal. Some decimal numbers will not be represented precisely. And unfortunately, since Javascript only has one Number class, it’s not a very good tool for this job. Other languages have decent decimal libraries designed to avoid precisely this kind of error. You’re going to have to either accept one-cent errors, implement a solution server-side, or work very hard to fix this.

    edit: ooh! you can do 78 * 7 * 725 and then divide by 10000, or to be even more precise just put the decimal point in the right place. Basically represent the tax rate as something other than a tiny fraction. Less convenient but it’ll probably take care of your multiplication errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to bind columns in a DataGridView to pull values from two different
I want to pull two values out from an array based on their index.
I want to write a RegEx to pull out all the variable values and
I'd like to pull values from textfiles in a directory and put these lists
Using SSRS2005, can you pull in values specified in the SSRS Web.Config file (think
I have a relation mysql database setup. and I want to pull all the
I am trying to pull together some data for a report and need to
In writing select statements in mySQL, if I want to pull records where a
Ok, So I want to display some attributes, but only if they have a
I'm trying to figure out how pull select values from a table column, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.