-5

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.

Subir
  • 130
  • 1
  • 3
  • 10

1 Answers1

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
  • @Subir, I doubled checked it, and I updated it. Check it now. – Rubens Mariuzzo Sep 01 '13 at 00:42
  • 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
  • You are right @jahroy – Rubens Mariuzzo Sep 01 '13 at 06:23