Built-in way to format numbers with a space after a character

Is there a built-in way to format a number with a space between the sign and the number?

Sign format: sprintf("%+0.2f", $number);

What I'm looking for is not necessarily with sprintf (doesn't work): sprintf("%+ 0.2f", $number);

+4
source share
1 answer

Do not think that this is supported, as it may just not be up to some ISO. I think when you add extra space after the sign, semantically it is no longer part of the number (do not quote me on this).

But fix it:

<?php

$n = str_replace(
    ['-', '+'],
    ['- ', '+ '],
    sprintf("%+0.2f", $number)
);
+3
source

Source: https://habr.com/ru/post/1648300/


All Articles