Marisa
asked on
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
[URL="http://www.stadriemblems.com/auto-quote.html"]Page containing calculator[/URL]
[URL="http://www.stadriemblems.com/sizecalc.js"]External file: sizecalc.js[/URL]
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
[URL="http://www.stadriemblems.com/auto-quote.html"]Page containing calculator[/URL]
[URL="http://www.stadriemblems.com/sizecalc.js"]External file: sizecalc.js[/URL]
ASKER
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!!!
Thank you!!!
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
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
ASKER
Yes, the first link I posted is the entire html page.
okay here in your auto_quote.htm
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;
}
to get it in 1/8 increments :)
Change this code
lines 11500 -11508
if (ok){
size = (parseFloat($('patch_width
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
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;
}
ASKER
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?
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?
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
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
ASKER
Well that's no good. 8 needs to = 8. So is there not a way to do this then?
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
size = (parseFloat($('patch_width
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
ASKER
Cool, thanks! Do I replace this or add it? I told you, I am JavaRetarded, hahaha
your welcome
to answer your question replace
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;
}
to answer your question replace
if (ok){
size = (parseFloat($('patch_width
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
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;
}
ASKER
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.
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;
}
size = (parseFloat($('patch_width
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;
}
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Was very patient with my ignorance and didn't give up.
and for your rounding...
http://www.javascriptkit.com/javatutors/round.shtml
:)