jQuery percentage calculation round up

0 votes

I have a payment form, the client requested an additional 2.5% charge on the total, after some playing I have come up with this:

$(document).ready(function(){
$('#amount').keyup(function(){
    $('#pay_amount').val($('#amount').val() * 1.025);
});   
});

You can see it working here: FIDDLE

My question/issue is can the total be rounded up/down to just two digits e.g. if you add the amount as "6" the total is: 6.1499999999999995 can this be 6.14 or rounded up to 6.15 Same if you enter "100"

Thanks

Aug 2, 2022 in Web Development by gaurav
• 23,260 points
1,988 views

1 answer to this question.

0 votes

If you just need the formatted string, you can use value. toFixed(2) . If you need the value to remain a number, then use Math. round(value * 100)/100 

answered Aug 2, 2022 by rajatha
• 7,640 points

Related Questions In Web Development

0 votes
0 answers

scroll up and down a div on button click using jquery

I am trying to add a feature ...READ MORE

Jun 29, 2022 in Web Development by gaurav
• 23,260 points
7,307 views
0 votes
0 answers

How to make notices pop up as jquery on Ruby on Rails 4

I have a user controller with the ...READ MORE

Jul 28, 2022 in Web Development by gaurav
• 23,260 points
259 views
0 votes
0 answers

jQuery and colour calculation

Currently I've got an H1 tag set ...READ MORE

Jul 28, 2022 in Web Development by gaurav
• 23,260 points
246 views
0 votes
1 answer

how to rotate image image 3d in jquery on swipe up and swipe down

If you're not using one of the ...READ MORE

answered Aug 4, 2022 in Web Development by rajatha
• 7,640 points
1,332 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
538 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
1,012 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,510 points
1,004 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,880 points
854 views
0 votes
1 answer

scrolling up with jquery waypoints

Look at the offset option someElements.waypoint(function(event, direction) { ...READ MORE

answered Jul 26, 2022 in Web Development by rajatha
• 7,640 points
969 views
0 votes
1 answer

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

To format a number using fixed-point notation, ...READ MORE

answered Aug 1, 2022 in Web Development by rajatha
• 7,640 points
4,962 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP