Welcome, Guest
Username: Password: Remember me

TOPIC: float with 2 decimals

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 ?
The administrator has disabled public write access.

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

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
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!!!
The administrator has disabled public write access.
Time to create page: 0.093 seconds

Get Started