Suppose I have a number like 1234
. I want to add new number 00
and ,
and €
at the end. Now number will be like 1234,00€
I can not figure out.
Asked
Active
Viewed 87 times
-5

Subir
- 130
- 1
- 3
- 10
-
You can do this with plain vanilla JS. – j08691 Aug 31 '13 at 16:24
-
2try `'1234€'.replace(/(€)$/, ',00$1')` – Arun P Johny Aug 31 '13 at 16:24
-
possible duplicate of [How can I format numbers as money in JavaScript?](http://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-money-in-javascript) – Pekka Aug 31 '13 at 16:25
-
try `alert('1234€'.replace(/(€)$/, ',00$1'));` – Tushar Gupta - curioustushar Aug 31 '13 at 16:26
-
Try this: `var s = 1234 + '00,€'` – jahroy Sep 01 '13 at 01:55
-
Calling `string.replace()` on a number won't work. – jahroy Sep 01 '13 at 02:04
-
jahroy@ Thank you vaery much. It work's for me. – Subir Sep 01 '13 at 03:46
1 Answers
3
That will work for you:
var value = '1234';
var formatted = value.replace(/(\d+)/, '$1,00€');
But, I strongly recommend you to read the answers in this question: How can I format numbers as money in JavaScript?
Update as @jared said, you can just concatenate the text: ,00€
to your number to just get the desired results.

Community
- 1
- 1

Rubens Mariuzzo
- 28,358
- 27
- 121
- 148
-
-
What's wrong with `var s = 1234 + '00,€'`? There's no need for regex, **or** `string.replace()` **and** there's no need to convert the original value to a string. Note that the OP is using a number (not a string). Trying to invoke `string.replace()` on a number will cause an error. – jahroy Sep 01 '13 at 02:01
-