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

  I found "cook" two days ago. Played around with it for a day and then within a day got rid of two legacy applications in IBM Lotus Domino Notes and replaced them with "cook". It was really easy. A piece of cake. Actually it was even easier than cooking. Cooking involves more work than developing with "cook". What can I say about "cook"? Great application great price for what it delivers great forum with a lot of information and fast responses active and friendly community fast forward moving development cycle So what should I say "Monsieur Le Cook"? Keep the good work going it will lead to success. Having become a paying member in the words of Edith Piaf may I say ..... non rien de rien ... je ne regrette rien. Vive La France.
FK (JED)
         

Get Started