perl / ifram / javascript question
Madison Kelly
linux-5ZoueyuiTZhBDgjK7y7TUQ at public.gmane.org
Wed Mar 14 13:49:25 UTC 2007
Andrej Marjan wrote:
> Madison Kelly wrote:
>> Hi all,
>>
>> I've got a thing I want to do with my web app that I know is
>> possible but can't for the life of me figure out... I've googled this
>> do death but am probably stumbling over something really simple.
>>
>> Anyway, I want to use perl to round a number (for now; later want to
>> submit a form without reloading the whole page).
>>
>> So I'd like to be able to have a javascript function pass a couple
>> variables to a perl script (ie:
>> 'http://foo.com/cgi-bin/script?num=<real_number>&precision=<precision>').
>> Then, once the perl script does it's magic, load the numbers into
>> hidden form fields via an iframe for the calling script to read).
>
> Well you could just do it in javascript, e.g. 1.563532.toPrecision(3) ==
> "1.56"
>
> Do you have a particular reason for wanting to do the rounding server-side?
>
> I don't know if there's a cleverer way to do it in Perl, but sprintf
> will do the trick, e.g. sprintf("%.2f", 1.5678).
In this case the problem is Javascript is not very good at rounding.
This is more of an issue because this is a financial program and a
rounding error could cost me money or, worse, charge a customer too much
money. Perhaps a penny here or there, but regardless, it would make me
look unprofessional.
That said, perl isn't perfect either but it is a lot easier to account
for it's short comings. I can't remember exactly how it was done but it
wasn't with sprintf alone... I wrote it for another program so I need to
write a new function from scratch but I know it can be done a lot more
reliably.
The need to tie it in with the Javascript is that as I or a user adds
items to an invoice I use JS to calculate a running subtotal/taxes/total
at the bottom. I have always planned to run the final calculations
through perl, so this would save me doing it twice, too.
Thanks for the reply!
Madi
--
The Toronto Linux Users Group. Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
More information about the Legacy
mailing list