<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vivek Kumar Bansal on Medium]]></title>
        <description><![CDATA[Stories by Vivek Kumar Bansal on Medium]]></description>
        <link>https://medium.com/@vkbansal?source=rss-35c868e0d32e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*okeYlfsyrLVdS_8u.jpg</url>
            <title>Stories by Vivek Kumar Bansal on Medium</title>
            <link>https://medium.com/@vkbansal?source=rss-35c868e0d32e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 04:11:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vkbansal/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Format INR currency in JavaScript]]></title>
            <link>https://medium.com/@vkbansal/format-inr-currency-in-javascript-812f46361856?source=rss-35c868e0d32e------2</link>
            <guid isPermaLink="false">https://medium.com/p/812f46361856</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[regex]]></category>
            <category><![CDATA[tips]]></category>
            <dc:creator><![CDATA[Vivek Kumar Bansal]]></dc:creator>
            <pubDate>Sat, 17 Dec 2016 14:08:42 GMT</pubDate>
            <atom:updated>2016-12-17T14:09:11.261Z</atom:updated>
            <content:encoded><![CDATA[<p>Formatting a number in JavaScript can be as simple as toLocaleString(), but while working on a side project, I came across a scenario where neither toLocaleString() nor toFixed() was enough.</p><p>I wanted the numbers to be in XX,XX,XXX.XX format. So, I tried bunch of different methods.</p><pre>(254.4).toLocaleString() // &quot;254.4&quot;<br>(1234567.8).toLocalString() // &quot;1,234,567.8&quot;<br>(1234567.8).toFixed(2) // &quot;1234567.80&quot;  Number((1234567.8).toFixed(2)).toLocaleString() // &quot;1,234,567.8&quot;</pre><p>As you can see that none of the methods worked as per my requirements.</p><p>After some googling and tinkering around with RegExp(s), I finally found a solution.</p><pre>(1234567.8).toFixed(2).replace(/(\d)(?=(\d{2})+\d\.)/g, &#39;$1,&#39;) // &quot;12,34,567.80&quot;</pre><p>The above solution works flawlessly as per my requirements. Basically the regex looks for a digit which is followed by digits (in groups of two) followed by a digit and a decimal point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*Qz4-Xv9JQSppTXgK6YVPpw.png" /><figcaption>Image Generated from http://jex.im/regulex</figcaption></figure><p>This article first appeared on <a href="https://vkbansal.me/blog/format-indian-currency-in-js">vkbansal.me</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=812f46361856" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>