Späť na zoznam skriptov

currencyFormat

This function formats a number as a currency, including currency sign, decimal and thousands separator.

syntax

string currencyFormat (int n, [str currencySign, bool currencySignPosition, str thousandsDivider, str decimalDivider, bool notForField]);

Function returns formated string from entered number n. Result is rounded to one decimal place and one zero is added at the end (so it has two decimal digits). If currencySign is defined, it is insert before or after the number (depending on currencySignPosition). Thousands are separated by given thousandsDivider, decimal separator is replaced with decimalDivider.

If you want to use result in the document (not in form field), you will probably want to replace spaces with non-breaking spaces. If so, set notForField to true.

example

enter number
result

compatibility

This script should work in all browsers with JavaScript support.

Súbory na stiahnutie

  Názov Typ Veľkosť
currency_format.js JavaScript 1.07 KB
Späť na zoznam skriptov