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

Really great Joomla tool Cook is a great piece of kit for creating Joomla components. It uses a drag-n-drop interface to build tables and fully featured pages. You can test your component in a sandbox before downloading it packaged up ready to install. The developer is responsive on the support forum.
Twev (JED)
          

Get Started