Forums

Format Calculation Result As Currency

dautrich 20 May, 2015
I've created an order form for sandwiches (s. screenshot Order_Form.jpg). It allows to order 0-9 units of 6 different variations of sandwiches. Whenever the user enters a digit into one of the six fields, the function calculate() is called [via an extra param [b]onchange=calculate()[/b]].

Here the function:
function calculate () {
var PG = 1.8;
var PE = 1.2;
var Preis = 0.0;
Sal = parseInt(jQuery("[name='Salami']").val());
SalG = parseInt(jQuery("[name='SalamiGarniert']").val());
Kas = parseInt(jQuery("[name='Käse']").val());
KasG = parseInt(jQuery("[name='KäseGarniert']").val());
Wur = parseInt(jQuery("[name='Wurst']").val());
WurG = parseInt(jQuery("[name='WurstGarniert']").val());
Preis = (SalG + KasG + WurG) * PG + (Sal + Kas + Wur) * PE;
Preis = Preis.toFixed(2);
jQuery("[name='Summe']").val(Preis);
}

The function works fine, but I would like to format the results es a €-value. Given the example from the screenshot, this would be "€ 4,80".
Is there an easy way to achieve that kind of formatting?



http://systemtest.mittelpunkt-aufenau.de/broetchen-bestellen.html
dautrich 20 May, 2015
Hello calculus00,
only registered und logged-in users will be able to see the order form!
GreyHead 21 May, 2015
Hi dautrich,

Please try:
jQuery("[name='Summe']").val('€ '+Preis);

Bob
dautrich 21 May, 2015
Answer
Hi Bob,
thanks for your proposal. I finally solved the problem. I used:
    jQuery("[name='Summe']").val("€ "+Preis);


But I also had to adjust some parameters in the Designer area.
See the screenshot attached for the final version.

Best regards,
Rolf
This topic is locked and no more replies can be posted.