# Price calculator and rounding

I am currently using a price calculator - although it's really not a calculator; I have to enter every price manually. Currently, it works in half inch increments.

I need it to do two things that it doesn't do currently:
1) Allow the customer to enter a dimension in 1/4 inch increments (1/8 would be even better, but I'm not requesting a miracle)
2) Make the result automatically round up to the nearest 1/2 inch

JavaScriptJScriptWeb Development

Last Comment
Marisa
plusone3055

if you have it already working in 1/2  increments why use the same fuction * .5   and then again *.25 for 1/4 and 1/8 increments

http://www.javascriptkit.com/javatutors/round.shtml

:)
Marisa

Sounds simple enough, however, I should have clarified that I know very little about JavaScript syntax; I took this code for somewhere else. Could you maybe be a little more specific in your explanation? Is this fuction * .5 that you refer to a setting in sizecalc.js?

Thank you!!!
plusone3055

thank you for clarifying :)

hold on a min lemmie look thorugh the script

can you please post the entire HTML page so i can see how you are referencing the javascript please
Marisa

Yes, the first link I posted is the entire html page.
plusone3055

to get it in 1/8 increments :)

Change this code
lines 11500 -11508

if (ok){
size = (parseFloat(\$('patch_width').value) + parseFloat(\$('patch_length').value)) / 2;
temp_size = size - Math.floor(size);
if (temp_size > 0.5){
size = Math.ceil(size);
}
else if (temp_size > 0 && temp_size <= 0.5){
size = Math.floor(size) + 0.5;
}
==========================================================================
To THIS

if (ok){
size = (parseFloat(\$('patch_width').value) + parseFloat(\$('patch_length').value)) / 8;
temp_size = size - Math.floor(size);
if (temp_size > 0.125){
size = Math.ceil(size);
}
else if (temp_size > 0 && temp_size <= 0.125){
size = Math.floor(size) + 0.125;
}
Marisa

Thanks! That works in a way, however, when I put in .125 x .5 it gives me a total of 1.

Or when I put in a total of .125 x 8 it gives me a total of 3.

So it's not doing the math correctly. Do I also need to edit the sizecalc.js file?
plusone3055

it is doing the match correctly you have to decide how the users need to enter the data..

Currently, it works in half inch increments.

I need it to do two things that it doesn't do currently:
1) Allow the customer to enter a dimension in 1/4 inch increments (1/8 would be even better, but I'm not requesting a miracle)

it was doing it in 1/2 inches
so that means  that if a user was entering 2 into the field that would be 1 whole inch

now its doing it in 1/8 inch each number is 1/8
so 8 = 1
Marisa

Well that's no good. 8 needs to = 8. So is there not a way to do this then?
plusone3055

if (ok){
size = (parseFloat(\$('patch_width').value) + parseFloat(\$('patch_length').value)) / 1;
temp_size = size - Math.floor(size);
if (temp_size > 0.0){
size = Math.ceil(size);
}
else if (temp_size > 0 && temp_size <= 0.0){
size = Math.floor(size) + 0.0;
}

for 8 = 8
Marisa

Cool, thanks! Do I replace this or add it? I told you, I am JavaRetarded, hahaha
plusone3055

if (ok){
size = (parseFloat(\$('patch_width').value) + parseFloat(\$('patch_length').value)) / 8;
temp_size = size - Math.floor(size);
if (temp_size > 0.125){
size = Math.ceil(size);
}
else if (temp_size > 0 && temp_size <= 0.125){
size = Math.floor(size) + 0.125;
}
=========================
WITH THIS
========================

if (ok){
size = (parseFloat(\$('patch_width').value) + parseFloat(\$('patch_length').value)) / 1;
temp_size = size - Math.floor(size);
if (temp_size > 0.0){
size = Math.ceil(size);
}
else if (temp_size > 0 && temp_size <= 0.0){
size = Math.floor(size) + 0.0;
}

Marisa

Boy, I really feel like I'm being a nuisance. Replacing that code gives the sum of the two dimensions rather than the average like it was doing before.
plusone3055

if (ok){
size = (parseFloat(\$('patch_width').value) + parseFloat(\$('patch_length').value)) / 2;
temp_size = size - Math.floor(size);
if (temp_size > 0.0){
size = Math.ceil(size);
}
else if (temp_size > 0 && temp_size <= 0.0){
size = Math.floor(size) + 0.0;
}
Marisa

Great! That worked! I should only have one more question. it's back to not working if I put in any increment smaller than .5.
plusone3055

THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Marisa

Was very patient with my ignorance and didn't give up.
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts

TRUSTED BY