---
title: "Currency Format in JavaScript"  
description: "<script type=\"text/javascript\">     function CurrencyFormat(amount) {         amount = amount.toString().replace(/\\$|\\,/g, '');         if (isNaN(amou"  
author: "AVADHESH PATEL"  
published: 2012-08-01  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/328/currency-format-in-javascript  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# Currency Format in JavaScript

Make function for return [currency](https://www.mindstick.com/articles/311850/currency-wars-what-they-are-and-how-they-work) [format](https://www.mindstick.com/forum/162083/how-to-convert-ost-files-into-pst-format)\

```
<script type="text/javascript"> function CurrencyFormat(amount)
{     amount = amount.toString().replace(/\$|\,/g,
'');        if (isNaN(amount))
{         amount = "0";}     sign
= (amount == (amount = Math.abs(amount)));           amount = Math.floor(amount * 100 +
0.50000000001);     cents = amount % 100;     amount
= Math.floor(amount / 100).toString();     if (cents
< 10) {         cents
= "0" + cents;     }     for (var i = 0; i < Math.floor((amount.length - (1 +
i)) / 3); i++)     {       amount = amount.substring(0, amount.length
- (4 * i + 3)) + ',' + amount.substring(amount.length - (4 * i +
3));     }     return (((sign) ? ''
: '-') + amount + '.'
+ cents);  }</script>
```

Call the above [javascript function](https://www.mindstick.com/forum/2090/send-data-from-asp-dot-net-code-behind-to-a-javascript-function) ‘CurrencyFormat’ on [textbox](https://www.mindstick.com/articles/320/textbox-control-in-vb-dot-net) [event](https://www.mindstick.com/articles/167719/marquee-hire-benefits-of-event-lighting-hire-london) ‘onblur’.

onblur="this.value=CurrencyFormat(this.value);

---

Original Source: https://www.mindstick.com/blog/328/currency-format-in-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
