1

I need to display '150000.50' in Indian number format with the last zero intact.

I followed the following, but the solution Previous answer doesn't completely solve the issue. It removes the last 0 from the number which is required in my case.

1.

preg_replace("/(\d+?)(?=(\d\d)+(\d)(?!\d))(\.\d+)?/i", "$1,", $num);
 // Output: 1,50,000.5 
// Expected output: 1,50,500.50
new NumberFormatter($locale = 'en_IN', NumberFormatter::DECIMAL); from Intl extension.
// Output: 1,50,000.5
// Expected output: 1,50,500.50

money_format is now deprecated. If anyone can update preg_replace function regex to preserve the trailing zero, it will be helpful.

Nandha
  • 192
  • 1
  • 2
  • 11
  • 1
    If you're asking about the same issue, then it's still a duplicate of that question - it is open for more answers to be added if people create them. We don't need the effort to be split between this question and that one. – ADyson Jul 19 '23 at 09:44
  • There appear to be examples using both `preg_replace` and `NumberFormatter` in the answers to the question you linked. Why are you asking again? – Jim Jul 19 '23 at 22:45
  • Does this answer your question? [How to display Currency in Indian Numbering Format in PHP?](https://stackoverflow.com/questions/10042485/how-to-display-currency-in-indian-numbering-format-in-php) – ryanwebjackson Jul 20 '23 at 00:14
  • Expected output is 1,50,000.50 Output given by all the suggested answers were 1,50,000.5 I added comment in the suggested answer for this, solutions. that's why I asked this as a new question. – Nandha Jul 20 '23 at 09:12

0 Answers0