CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 How to retain float format

Print topic Send  topic

Author Message
Gary Finlay
Posted: 02/02/2005, 4:13 PM

I'm priming some fields on a record form in the "Before Show" event with a
float value and it correctly displays the value and the correct format
(0.00).

Then I calculate these values in a field's "On Change" event and although it
works and displays the correct value, it loses its formatting and I get for
example 20 instead of 20.00

I use the following code to calculate the values and its after this is
executed that the format changes...

document.bookings.FeeTotal.value = document.bookings.Participants.value *
document.bookings.Fee.value;

You can see what I mean by looking here...

http://www.boreenrun.com/bookings/BookingForm.php

Change the value in the first "Quantity" field and see how the format in the
"Amount" column changes but loses its format.

Any idea how I would retain the format?

Regards
Gary Finlay

Jim Crews
Posted: 02/02/2005, 6:24 PM

Have you already tried formatting the float field
#,###.00

"Gary Finlay" <throw.away3@ntlworld.com> wrote in message
news:ctrqb3$p4e$1@news.codecharge.com...
> I'm priming some fields on a record form in the "Before Show" event with a
> float value and it correctly displays the value and the correct format
> (0.00).
>
> Then I calculate these values in a field's "On Change" event and although
> it works and displays the correct value, it loses its formatting and I get
> for example 20 instead of 20.00
>
> I use the following code to calculate the values and its after this is
> executed that the format changes...
>
> document.bookings.FeeTotal.value = document.bookings.Participants.value *
> document.bookings.Fee.value;
>
> You can see what I mean by looking here...
>
> http://www.boreenrun.com/bookings/BookingForm.php
>
> Change the value in the first "Quantity" field and see how the format in
> the "Amount" column changes but loses its format.
>
> Any idea how I would retain the format?
>
> Regards
> Gary Finlay
>
>

Gary Finlay
Posted: 02/03/2005, 3:12 AM

Ji Jim, yes I've already done that. This is the reply I got from CCS
support...
-----------------------------------------------------------------
I checked your page and I see that you do calculation on a client side. But
the number format you set in CCS project is applied on server side and when
JS code executes that format does nothing to the calculated value.
You need to apply formatting on a client side, in your JS code.
-----------------------------------------------------------------
This presumably means I have to apply some formatting in JS after I
calculate the value with...

>> document.bookings.FeeTotal.value = document.bookings.Participants.value *
>> document.bookings.Fee.value;

Any idea what JS function I'd use to do this?



"Jim Crews" <jcrews@umcsc.org> wrote in message
news:cts21q$ttt$1@news.codecharge.com...
> Have you already tried formatting the float field
> #,###.00
>
> "Gary Finlay" <throw.away3@ntlworld.com> wrote in message
>news:ctrqb3$p4e$1@news.codecharge.com...
>> I'm priming some fields on a record form in the "Before Show" event with
>> a float value and it correctly displays the value and the correct format
>> (0.00).
>>
>> Then I calculate these values in a field's "On Change" event and although
>> it works and displays the correct value, it loses its formatting and I
>> get for example 20 instead of 20.00
>>
>> I use the following code to calculate the values and its after this is
>> executed that the format changes...
>>
>> document.bookings.FeeTotal.value = document.bookings.Participants.value *
>> document.bookings.Fee.value;
>>
>> You can see what I mean by looking here...
>>
>> http://www.boreenrun.com/bookings/BookingForm.php
>>
>> Change the value in the first "Quantity" field and see how the format in
>> the "Amount" column changes but loses its format.
>>
>> Any idea how I would retain the format?
>>
>> Regards
>> Gary Finlay
>>
>>
>
>

Jim Crews
Posted: 02/03/2005, 8:56 AM

Name the function as formatCurrency and include a parameter called as num.
This function will be called in the input box. That I'll explain to you in
the end of the article.
function formatCurrency(num) {

Now in order to make sure that the number is entered correctly and no extra
characters are added, use the below line. Then Enter the desired currency in
the CurrencySymbol variable.

num = num.toString().replace(/\$|\,/g,'');
CurrencySymbol = "$"; // This you can change to any currency you may wish to
display.

Now we check wether the entered number is a valid numerical format or not.
Then we look for the number of decimals and tag them next to the number

if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));

Once done, then we return the function by formatting it in the desired
currency format.
return (((sign)?'':'-') + CurrencySumbol + num + '.' + cents);
}

from http://www.developersdex.com/gurus/articles/473.asp

"Gary Finlay" <throw.away3@ntlworld.com> wrote in message
news:ctt0v8$j03$1@news.codecharge.com...
> Ji Jim, yes I've already done that. This is the reply I got from CCS
> support...
> -----------------------------------------------------------------
> I checked your page and I see that you do calculation on a client side.
> But the number format you set in CCS project is applied on server side and
> when JS code executes that format does nothing to the calculated value.
> You need to apply formatting on a client side, in your JS code.
> -----------------------------------------------------------------
> This presumably means I have to apply some formatting in JS after I
> calculate the value with...
>
>>> document.bookings.FeeTotal.value = document.bookings.Participants.value
>>> * document.bookings.Fee.value;
>
> Any idea what JS function I'd use to do this?
>
>
>
> "Jim Crews" <jcrews@umcsc.org> wrote in message
>news:cts21q$ttt$1@news.codecharge.com...
>> Have you already tried formatting the float field
>> #,###.00
>>
>> "Gary Finlay" <throw.away3@ntlworld.com> wrote in message
>>news:ctrqb3$p4e$1@news.codecharge.com...
>>> I'm priming some fields on a record form in the "Before Show" event with
>>> a float value and it correctly displays the value and the correct format
>>> (0.00).
>>>
>>> Then I calculate these values in a field's "On Change" event and
>>> although it works and displays the correct value, it loses its
>>> formatting and I get for example 20 instead of 20.00
>>>
>>> I use the following code to calculate the values and its after this is
>>> executed that the format changes...
>>>
>>> document.bookings.FeeTotal.value = document.bookings.Participants.value
>>> * document.bookings.Fee.value;
>>>
>>> You can see what I mean by looking here...
>>>
>>> http://www.boreenrun.com/bookings/BookingForm.php
>>>
>>> Change the value in the first "Quantity" field and see how the format in
>>> the "Amount" column changes but loses its format.
>>>
>>> Any idea how I would retain the format?
>>>
>>> Regards
>>> Gary Finlay
>>>
>>>
>>
>>
>
>

Gary Finlay
Posted: 02/03/2005, 11:29 AM

Thanks Jim for your help. I've included that function in functions.js and
changed my code to...

document.bookings.FeeTotal.value=formatCurrency(document.bookings.Participants.value)
* (document.bookings.Fee.value);

but unfortunately it doesn't work. Does the line above look ok to you?



"Jim Crews" <jcrews@umcsc.org> wrote in message
news:cttl4k$349$1@news.codecharge.com...
> Name the function as formatCurrency and include a parameter called as num.
> This function will be called in the input box. That I'll explain to you in
> the end of the article.
> function formatCurrency(num) {
>
> Now in order to make sure that the number is entered correctly and no
> extra characters are added, use the below line. Then Enter the desired
> currency in the CurrencySymbol variable.
>
> num = num.toString().replace(/\$|\,/g,'');
> CurrencySymbol = "$"; // This you can change to any currency you may wish
> to display.
>
> Now we check wether the entered number is a valid numerical format or not.
> Then we look for the number of decimals and tag them next to the number
>
> if(isNaN(num))
> num = "0";
> sign = (num == (num = Math.abs(num)));
> num = Math.floor(num*100+0.50000000001);
> cents = num%100;
> num = Math.floor(num/100).toString();
> if(cents<10)
> cents = "0" + cents;
> for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
> num = num.substring(0,num.length-(4*i+3))+','+
> num.substring(num.length-(4*i+3));
>
> Once done, then we return the function by formatting it in the desired
> currency format.
> return (((sign)?'':'-') + CurrencySumbol + num + '.' + cents);
> }
>
> from http://www.developersdex.com/gurus/articles/473.asp
>
> "Gary Finlay" <throw.away3@ntlworld.com> wrote in message
>news:ctt0v8$j03$1@news.codecharge.com...
>> Ji Jim, yes I've already done that. This is the reply I got from CCS
>> support...
>> -----------------------------------------------------------------
>> I checked your page and I see that you do calculation on a client side.
>> But the number format you set in CCS project is applied on server side
>> and when JS code executes that format does nothing to the calculated
>> value.
>> You need to apply formatting on a client side, in your JS code.
>> -----------------------------------------------------------------
>> This presumably means I have to apply some formatting in JS after I
>> calculate the value with...
>>
>>>> document.bookings.FeeTotal.value = document.bookings.Participants.value
>>>> * document.bookings.Fee.value;
>>
>> Any idea what JS function I'd use to do this?
>>
>>
>>
>> "Jim Crews" <jcrews@umcsc.org> wrote in message
>>news:cts21q$ttt$1@news.codecharge.com...
>>> Have you already tried formatting the float field
>>> #,###.00
>>>
>>> "Gary Finlay" <throw.away3@ntlworld.com> wrote in message
>>>news:ctrqb3$p4e$1@news.codecharge.com...
>>>> I'm priming some fields on a record form in the "Before Show" event
>>>> with a float value and it correctly displays the value and the correct
>>>> format (0.00).
>>>>
>>>> Then I calculate these values in a field's "On Change" event and
>>>> although it works and displays the correct value, it loses its
>>>> formatting and I get for example 20 instead of 20.00
>>>>
>>>> I use the following code to calculate the values and its after this is
>>>> executed that the format changes...
>>>>
>>>> document.bookings.FeeTotal.value = document.bookings.Participants.value
>>>> * document.bookings.Fee.value;
>>>>
>>>> You can see what I mean by looking here...
>>>>
>>>> http://www.boreenrun.com/bookings/BookingForm.php
>>>>
>>>> Change the value in the first "Quantity" field and see how the format
>>>> in the "Amount" column changes but loses its format.
>>>>
>>>> Any idea how I would retain the format?
>>>>
>>>> Regards
>>>> Gary Finlay
>>>>
>>>>
>>>
>>>
>>
>>
>
>

Jim Crews
Posted: 02/03/2005, 4:20 PM

unsure, but try http://www.javascriptkit.com/javatutors/formatnumber.shtml


"Gary Finlay" <throw.away3@ntlworld.com> wrote in message
news:cttu1u$9s5$1@news.codecharge.com...
> Thanks Jim for your help. I've included that function in functions.js and
> changed my code to...
>
> document.bookings.FeeTotal.value=formatCurrency(document.bookings.Participants.value)
> * (document.bookings.Fee.value);
>
> but unfortunately it doesn't work. Does the line above look ok to you?
>
>
>
> "Jim Crews" <jcrews@umcsc.org> wrote in message
>news:cttl4k$349$1@news.codecharge.com...
>> Name the function as formatCurrency and include a parameter called as
>> num. This function will be called in the input box. That I'll explain to
>> you in the end of the article.
>> function formatCurrency(num) {
>>
>> Now in order to make sure that the number is entered correctly and no
>> extra characters are added, use the below line. Then Enter the desired
>> currency in the CurrencySymbol variable.
>>
>> num = num.toString().replace(/\$|\,/g,'');
>> CurrencySymbol = "$"; // This you can change to any currency you may wish
>> to display.
>>
>> Now we check wether the entered number is a valid numerical format or
>> not. Then we look for the number of decimals and tag them next to the
>> number
>>
>> if(isNaN(num))
>> num = "0";
>> sign = (num == (num = Math.abs(num)));
>> num = Math.floor(num*100+0.50000000001);
>> cents = num%100;
>> num = Math.floor(num/100).toString();
>> if(cents<10)
>> cents = "0" + cents;
>> for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
>> num = num.substring(0,num.length-(4*i+3))+','+
>> num.substring(num.length-(4*i+3));
>>
>> Once done, then we return the function by formatting it in the desired
>> currency format.
>> return (((sign)?'':'-') + CurrencySumbol + num + '.' + cents);
>> }
>>
>> from http://www.developersdex.com/gurus/articles/473.asp
>>
>> "Gary Finlay" <throw.away3@ntlworld.com> wrote in message
>>news:ctt0v8$j03$1@news.codecharge.com...
>>> Ji Jim, yes I've already done that. This is the reply I got from CCS
>>> support...
>>> -----------------------------------------------------------------
>>> I checked your page and I see that you do calculation on a client side.
>>> But the number format you set in CCS project is applied on server side
>>> and when JS code executes that format does nothing to the calculated
>>> value.
>>> You need to apply formatting on a client side, in your JS code.
>>> -----------------------------------------------------------------
>>> This presumably means I have to apply some formatting in JS after I
>>> calculate the value with...
>>>
>>>>> document.bookings.FeeTotal.value =
>>>>> document.bookings.Participants.value * document.bookings.Fee.value;
>>>
>>> Any idea what JS function I'd use to do this?
>>>
>>>
>>>
>>> "Jim Crews" <jcrews@umcsc.org> wrote in message
>>>news:cts21q$ttt$1@news.codecharge.com...
>>>> Have you already tried formatting the float field
>>>> #,###.00
>>>>
>>>> "Gary Finlay" <throw.away3@ntlworld.com> wrote in message
>>>>news:ctrqb3$p4e$1@news.codecharge.com...
>>>>> I'm priming some fields on a record form in the "Before Show" event
>>>>> with a float value and it correctly displays the value and the correct
>>>>> format (0.00).
>>>>>
>>>>> Then I calculate these values in a field's "On Change" event and
>>>>> although it works and displays the correct value, it loses its
>>>>> formatting and I get for example 20 instead of 20.00
>>>>>
>>>>> I use the following code to calculate the values and its after this is
>>>>> executed that the format changes...
>>>>>
>>>>> document.bookings.FeeTotal.value =
>>>>> document.bookings.Participants.value * document.bookings.Fee.value;
>>>>>
>>>>> You can see what I mean by looking here...
>>>>>
>>>>> http://www.boreenrun.com/bookings/BookingForm.php
>>>>>
>>>>> Change the value in the first "Quantity" field and see how the format
>>>>> in the "Amount" column changes but loses its format.
>>>>>
>>>>> Any idea how I would retain the format?
>>>>>
>>>>> Regards
>>>>> Gary Finlay
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>

Gary Finlay
Posted: 02/06/2005, 4:28 PM

Sorted it. There is a misprint in the function that I cut and pasted from
the website. See it below... CurrencySumbol instead of CurrencySymbol

Thanks for your help Jim. Its working nicely now.


"Jim Crews" <jcrews@umcsc.org> wrote in message
news:ctuf48$n7s$1@news.codecharge.com...
> unsure, but try http://www.javascriptkit.com/javatutors/formatnumber.shtml
>
>
> "Gary Finlay" <throw.away3@ntlworld.com> wrote in message
>news:cttu1u$9s5$1@news.codecharge.com...
>> Thanks Jim for your help. I've included that function in functions.js
>> and changed my code to...
>>
>> document.bookings.FeeTotal.value=formatCurrency(document.bookings.Participants.value)
>> * (document.bookings.Fee.value);
>>
>> but unfortunately it doesn't work. Does the line above look ok to you?
>>
>>
>>
>> "Jim Crews" <jcrews@umcsc.org> wrote in message
>>news:cttl4k$349$1@news.codecharge.com...
>>> Name the function as formatCurrency and include a parameter called as
>>> num. This function will be called in the input box. That I'll explain to
>>> you in the end of the article.
>>> function formatCurrency(num) {
>>>
>>> Now in order to make sure that the number is entered correctly and no
>>> extra characters are added, use the below line. Then Enter the desired
>>> currency in the CurrencySymbol variable.
>>>
>>> num = num.toString().replace(/\$|\,/g,'');
>>> CurrencySymbol = "$"; // This you can change to any currency you may
>>> wish to display.
>>>
>>> Now we check wether the entered number is a valid numerical format or
>>> not. Then we look for the number of decimals and tag them next to the
>>> number
>>>
>>> if(isNaN(num))
>>> num = "0";
>>> sign = (num == (num = Math.abs(num)));
>>> num = Math.floor(num*100+0.50000000001);
>>> cents = num%100;
>>> num = Math.floor(num/100).toString();
>>> if(cents<10)
>>> cents = "0" + cents;
>>> for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
>>> num = num.substring(0,num.length-(4*i+3))+','+
>>> num.substring(num.length-(4*i+3));
>>>
>>> Once done, then we return the function by formatting it in the desired
>>> currency format.
>>> return (((sign)?'':'-') + CurrencySumbol + num + '.' + cents);
>>> }
>>>
>>> from http://www.developersdex.com/gurus/articles/473.asp
>>>
>>> "Gary Finlay" <throw.away3@ntlworld.com> wrote in message
>>>news:ctt0v8$j03$1@news.codecharge.com...
>>>> Ji Jim, yes I've already done that. This is the reply I got from CCS
>>>> support...
>>>> -----------------------------------------------------------------
>>>> I checked your page and I see that you do calculation on a client side.
>>>> But the number format you set in CCS project is applied on server side
>>>> and when JS code executes that format does nothing to the calculated
>>>> value.
>>>> You need to apply formatting on a client side, in your JS code.
>>>> -----------------------------------------------------------------
>>>> This presumably means I have to apply some formatting in JS after I
>>>> calculate the value with...
>>>>
>>>>>> document.bookings.FeeTotal.value =
>>>>>> document.bookings.Participants.value * document.bookings.Fee.value;
>>>>
>>>> Any idea what JS function I'd use to do this?
>>>>
>>>>
>>>>
>>>> "Jim Crews" <jcrews@umcsc.org> wrote in message
>>>>news:cts21q$ttt$1@news.codecharge.com...
>>>>> Have you already tried formatting the float field
>>>>> #,###.00
>>>>>
>>>>> "Gary Finlay" <throw.away3@ntlworld.com> wrote in message
>>>>>news:ctrqb3$p4e$1@news.codecharge.com...
>>>>>> I'm priming some fields on a record form in the "Before Show" event
>>>>>> with a float value and it correctly displays the value and the
>>>>>> correct format (0.00).
>>>>>>
>>>>>> Then I calculate these values in a field's "On Change" event and
>>>>>> although it works and displays the correct value, it loses its
>>>>>> formatting and I get for example 20 instead of 20.00
>>>>>>
>>>>>> I use the following code to calculate the values and its after this
>>>>>> is executed that the format changes...
>>>>>>
>>>>>> document.bookings.FeeTotal.value =
>>>>>> document.bookings.Participants.value * document.bookings.Fee.value;
>>>>>>
>>>>>> You can see what I mean by looking here...
>>>>>>
>>>>>> http://www.boreenrun.com/bookings/BookingForm.php
>>>>>>
>>>>>> Change the value in the first "Quantity" field and see how the format
>>>>>> in the "Amount" column changes but loses its format.
>>>>>>
>>>>>> Any idea how I would retain the format?
>>>>>>
>>>>>> Regards
>>>>>> Gary Finlay
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>


Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.