TOPIC:

Replace comma with point for calculation 2 weeks 4 days ago #242818

  • Topic Author
  • macross
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 30
  • Thanks: 0
Hello once again!
My form calculates a sum based on input fields. Since I live in Germany users tend to input Numbers with a comma instead of a point - which ruins my calculation.
I tried to convert the comma to a point with
.replace(",", ".")
but that doesn't do the trick... Calculation doesn't work anymore. What else could I try?
Thank you for answering my many questions ;)

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

Replace comma with point for calculation 2 weeks 4 days ago #242819

  • Eddy.vh's Avatar
  • Eddy.vh
  • Offline
  • Gold Breezer
  • Gold Breezer
  • Posts: 350
  • Karma: 3
  • Thanks: 57
Hallo,

Die Funktion .replace ist schon richtig.
    var tmp1 = ff_getElementByName('field1').value.replace(/,/g, ".");
    var tmp2 = ff_getElementByName('field2').value.replace(/,/g, ".");
    var tmp3 = Number(tmp1) + Number(tmp2);

    ff_getElementByName('total') = tmp3.toString().replace(".", ",");

mfG.,

Eddy
The following user(s) said Thank You: macross

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

Replace comma with point for calculation 2 weeks 4 days ago #242820

  • tihana.krivic's Avatar
  • tihana.krivic
  • Offline
  • Moderator
  • Moderator
  • Posts: 233
  • Karma: 3
  • Thanks: 40
Hi,

For example let say that you have two fields: (number1, number2, total)

To make this work with point as you want, please put this code in the Actionscript of the first element named number1:
function ff_number1_action(element, action)
{
var first= ff_getElementByName('number1').value.replace(/./g, ',');
var second= ff_getElementByName('number2').value.replace(/./g, ',');

var third =
Number(first) +
Number(second);

ff_getElementByName('total').value = third.toString().replace(",", ".");

}

In the Actionscript of the second element named number2 put this code:
function ff_number2_action(element, action)
{
var first= ff_getElementByName('number1').value.replace(/./g, ',');
var second= ff_getElementByName('number2').value.replace(/./g, ',');

var third =
Number(first) +
Number(second);

ff_getElementByName('total').value = third.toString().replace(",", ".");
}

Let me know if it helps.

@Eddy.vh
I did not notice that you had already answered :lol::lol:
I didn't reload the page


Regards,
Tihana
The following user(s) said Thank You: Eddy.vh, macross

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

Last edit: Post by tihana.krivic.

Replace comma with point for calculation 2 weeks 4 days ago #242821

  • Eddy.vh's Avatar
  • Eddy.vh
  • Offline
  • Gold Breezer
  • Gold Breezer
  • Posts: 350
  • Karma: 3
  • Thanks: 57
Hi Tihana,

It's all right, better two answers than none. ;)

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

Replace comma with point for calculation 2 weeks 4 days ago #242827

  • Topic Author
  • macross
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 30
  • Thanks: 0
Thank you so much for these fast answers!
Works like a charm! I also managed to subtract a possibly entered € symbol this way.

Just one more thing: If I want the total value to always display two decimal places, how would I add that to this?

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

Replace comma with point for calculation 2 weeks 4 days ago #242829

  • tihana.krivic's Avatar
  • tihana.krivic
  • Offline
  • Moderator
  • Moderator
  • Posts: 233
  • Karma: 3
  • Thanks: 40
Hi,

Example:
ff_getElementByName('total').value ="€" +  third.toString().replace(",", ".");  //add euro

Example for 2decimal place:
ff_getElementByName('total').value = third.toFixed(2) + ' €';

please adjust as you wish, this is just an example

Let me know if it helps.

Regards,
Tihana
The following user(s) said Thank You: macross

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

Last edit: Post by tihana.krivic.
Moderators: ForumSupport
Time to create page: 0.055 seconds

July Sale!

Discounts for all of our extensions + support. Ending July 31st!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!