Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

float with 2 decimals 22 Feb 2013 15:07 #6831

Hi, I have some number fields FLOAT
<field name="price_9"
label="ORDERFORMS_FIELD_PRICE_9"
alias="price_9"
default="0.00"
filter="FLOAT"
type="cktext"/>

I would like to force them to add the .00 or the decimal when the user introduces the data !

On the other hand,
I calculate the total by doing:
var cost1 = jQuery("#jform_price_1").val();
var cost2 = jQuery('#jform_price_2').val();
var total = parseFloat(cost1) + parseFloat(cost2);
jQuery('#jform_total_price').val(total);

And i obtain values not correct, any idea ?

Please Log in or Create an account to join the conversation.

Re: float with 2 decimals 22 Feb 2013 15:20 #6833

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
Hi @robertocook,

I've written quite extensively on using decimals in the RegEx section. Please check that out.

Also, I note from your code that you are actually using a FLOAT field and NOT a DECIMAL. I wouldn't really advise this as FLOATS are only really useful when calculating very precisely - for instance, scientific calculations where the number of digits past the point will probably change. This isn't really applicable to price since we don't use half or quarter-cent coins. E.g. you won't have a price such as $99.3333333, right?

Therefore, I would advise switching to decimal field type.

Hope it helps.

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.076 seconds

Although I found this tool some time ago I just started learning experimenting and building this first component on Monday and now on Thursday afternoon it's already online. Although I already had a working version done with another tool this is much easier to build and at the end you have the freedom to own your own component. Once you know how to use Cook you will boost your productivity as the learning curve is really moderate compared to many other tools.
Giori (Forum)

Get Started