Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

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]
0
Marisa
Asked:
Marisa
  • 8
  • 8
1 Solution
 
plusone3055Commented:
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

and for your rounding...
http://www.javascriptkit.com/javatutors/round.shtml

:)
0
 
MarisaWeb DesignAuthor Commented:
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!!!
0
 
plusone3055Commented:
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
MarisaWeb DesignAuthor Commented:
Yes, the first link I posted is the entire html page.
0
 
plusone3055Commented:
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;
                        }
0
 
MarisaWeb DesignAuthor Commented:
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?
0
 
plusone3055Commented:
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
0
 
MarisaWeb DesignAuthor Commented:
Well that's no good. 8 needs to = 8. So is there not a way to do this then?
0
 
plusone3055Commented:
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
0
 
MarisaWeb DesignAuthor Commented:
Cool, thanks! Do I replace this or add it? I told you, I am JavaRetarded, hahaha
0
 
plusone3055Commented:
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;
                        }


0
 
MarisaWeb DesignAuthor Commented:
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.
0
 
plusone3055Commented:
   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;
                        }
0
 
MarisaWeb DesignAuthor Commented:
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.
0
 
plusone3055Commented:
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;
                        }
0
 
MarisaWeb DesignAuthor Commented:
Was very patient with my ignorance and didn't give up.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 8
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now