Avatar of Marisa
MarisaFlag for United States of America

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]
JavaScriptJScriptWeb Development

Avatar of undefined
Last Comment
Marisa
Avatar of plusone3055
plusone3055
Flag of United States of America image

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

:)
Avatar of Marisa
Marisa
Flag of United States of America image

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!!!
Avatar of plusone3055
plusone3055
Flag of United States of America image

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
Avatar of Marisa
Marisa
Flag of United States of America image

ASKER

Yes, the first link I posted is the entire html page.
Avatar of plusone3055
plusone3055
Flag of United States of America image

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;
                        }
Avatar of Marisa
Marisa
Flag of United States of America image

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?
Avatar of plusone3055
plusone3055
Flag of United States of America image

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
Avatar of Marisa
Marisa
Flag of United States of America image

ASKER

Well that's no good. 8 needs to = 8. So is there not a way to do this then?
Avatar of plusone3055
plusone3055
Flag of United States of America image

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
Avatar of Marisa
Marisa
Flag of United States of America image

ASKER

Cool, thanks! Do I replace this or add it? I told you, I am JavaRetarded, hahaha
Avatar of plusone3055
plusone3055
Flag of United States of America image

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;
                        }


Avatar of Marisa
Marisa
Flag of United States of America image

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.
Avatar of plusone3055
plusone3055
Flag of United States of America image

   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;
                        }
Avatar of Marisa
Marisa
Flag of United States of America image

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
Avatar of plusone3055
plusone3055
Flag of United States of America image

Blurred text
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.
See Pricing Options
Start Free Trial
Avatar of Marisa
Marisa
Flag of United States of America image

ASKER

Was very patient with my ignorance and didn't give up.
JavaScript
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
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo