jQuery - Round to 2 decimal places and calculate with that number

0 votes

How to round the tax and brutto values to 2 decimal places...

I have tried to use .toFixed(2) but that returns a string and then i can't calculate with it anymore.

If someone could update the fiddle and make it work please?

And try to input number 23

DEMO Fiddle

// calculate brutto and tax
$(document).on('keyup paste', '#netto', function () {

  var netto = $("#netto").val();
  $("#brutto").val(netto * 1.19).toFixed(2);
  var brutto = $("#brutto").val();
  $("#tax").val(brutto - netto);

});

Aug 1 in Web Development by gaurav
• 17,580 points
31 views

1 answer to this question.

0 votes

To format a number using fixed-point notation, you can simply use the toFixed method:

(10.8).toFixed(2); // "10.80"

var num = 2.4;
alert(num.toFixed(2)); // "2.40"

Note that toFixed() returns a string.

IMPORTANT: Note that toFixed does not round 90% of the time, it will return the rounded value, but for many cases, it doesn't work.

For instance:

2.005.toFixed(2) === "2.00"

answered Aug 1 by rajatha
• 7,040 points

Related Questions In Web Development

0 votes
0 answers

how to spin and stop wheel has custom position with jquery

this i my code. I am using this ...READ MORE

Jul 27 in Web Development by gaurav
• 17,580 points
12 views
0 votes
0 answers

how to convert a decimal number to fraction using jquery

I want to convert the decimal number ...READ MORE

Jul 28 in Web Development by gaurav
• 17,580 points
10 views
0 votes
0 answers

How to update HTML element with jQuery and Galleria?

I am using Galleria for a slideshow. ...READ MORE

5 days ago in Web Development by gaurav
• 17,580 points
7 views
0 votes
1 answer

How to hide a div with jQuery?

We hide the divs by adding a CSS ...READ MORE

answered Jun 27 in Web Development by rajatha
• 7,040 points
22 views
0 votes
1 answer

How to use jquery with asp.net ajax?

If you weren't aware, Microsoft is planning ...READ MORE

answered Oct 15, 2018 in IoT (Internet of Things) by Annie97
• 2,160 points
190 views
0 votes
1 answer

Is 'sparkline' a method?

I suggest you to check 2 things That jquery.sparkline.js is actually ...READ MORE

answered Nov 9, 2018 in Apache Spark by Frankie
• 9,830 points
602 views
0 votes
1 answer

What is jQuery?

Hey, jQuery is a fast and concise JavaScript ...READ MORE

answered Feb 14, 2020 in JQuery by kartik
• 37,500 points
308 views
0 votes
1 answer

Error: Global Variable is not accessable to local function

Hey kartik, A variable declared outside a function has a ...READ MORE

answered Feb 19, 2020 in PHP by Niroj
• 82,740 points
283 views
0 votes
1 answer
0 votes
1 answer

How to use JQuery with ReactJS

Yes, we can use jQuery in ReactJs. ...READ MORE

answered Jun 22 in Web Development by rajatha
• 7,040 points
16 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP