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.094 seconds

For starters it's just so easy to design an app in a way that I'm used to i.e. database first then views followed by customization. The fork system is pure brilliance from a developer standpoint as I can override things and still add and update my projects with minimal effort! Truly amazing to be able to build components in Joomla using incremental refinement without having to do everything by hand. Thanks for the great tool! I am so much more productive now than ever and I can't imagine building components any other way!!!!
Dave (Forum)

Get Started