Thx

This snippet is anyway only thought as a base. It needs to be customized for your requirements. I found this solution nice because it is short and easy to understand (and to debug!). Accordingly you can easily add features in JavaScript or PERL without ending up with a code monster. I use the same principle for example to format the IBAN account number (a financial standard to identify an account made of 12 to 34 alphanumeric characters) for display purposes.

As I searched the net I found a lot of solutions with regexp especially in the area of JavaScript. Things like /\B(?=(\d{3})+(?!\d))/'/g, if it may inspire you. I tried two or three of them and gave up because they did not work.

An expert in C would also tell you, there is a solution with the printf function family. Not being an expert, I could not find a format mask allowing for any number size (in fact it takes more time to read the man page than to write this).

Effectively this code is loosing the signs. It was designed to format amounts for a banking application. In this application the amounts are always positive. So I did not have the issue.

K

The best medicine against depression is a cold beer!

In reply to Re^2: Formating numbers with thousand separator - Solution for web-applications by Zzenmonk
in thread Formating numbers with thousand separator - Solution for web-applications by Zzenmonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.