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 in Web Development by gaurav
• 17,580 points
11 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 by rajatha
• 7,040 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 in Web Development by gaurav
• 17,580 points
199 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 in Web Development by gaurav
• 17,580 points
7 views
0 votes
0 answers

jQuery and colour calculation

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

Jul 28 in Web Development by gaurav
• 17,580 points
8 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 in Web Development by rajatha
• 7,040 points
8 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

scrolling up with jquery waypoints

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

answered Jul 26 in Web Development by rajatha
• 7,040 points
10 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 in Web Development by rajatha
• 7,040 points
31 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