Search code examples
phpcurrency-formatting

Inverse format currency symbol php


So I am trying to inverse the value and the symbol that are being returned from:

 numfmt_format_currency($currencyFormatter, $value, $formatValue())

This code gives me:

 4$

And I want to inverse it like:

 $4

Not sure how to do it because the function must take all the parameters.. If anyone has some ideas I would appreciate it.


Solution

  • You could define your proper NumberFormat and set your own pattern, here is an exemple :

    <?php
    
    $formatter = new NumberFormatter('us_US',  NumberFormatter::CURRENCY);
    $formatter->setPattern('¤#,##0.00');
    echo numfmt_format_currency($formatter, 4, 'USD');
    
    ?>
    

    Result :

    $4.00