Global number format

Hi,

When doing something like this (let’s say fontSizeH1 value is 56 from the panel):

h1{font-size:' . $newSite->fontSizeH1()->value()/16 . 'rem}';

Depending on the server… sometimes the output is h1{font-size:3.5rem}; sometimes it’s h1{font-size:3,5rem}; and in that case the css breaks.

This fixes the issue (I could also use number_format but in this case the value isn’t big enough to care about thousands separator):

h1{font-size:' . str_replace(',', '.', $newSite->fontSizeH2()->value()/16) . 'rem}';

Is there a way to set a default Kirby number format? Anytime I do a calculation I need to do the number_format which is very repetitive.

You could set the locale for numbers unless you need the decimal comma for other numbers in your site.

In that case, I’d create a field method that will make your code clean, no matter if you use string replacement or number_format.

Thanks. Is there a locale that outputs numerics as 12345678910.5? I need all my calculations as the example above to have an output that is CSS friendly. Maybe I’m doing something wrong in the first place… feels I’m overcomplicating a simple arithmetic operation.

Stupid example:
1000041/2 = 500020.5 (not 500.020,5 or 500 020.5)


As a test I played with the locale setting but it doesn’t seem to have any impact on the output. I tried to add the following to my config.php:

'locale' => 'it_IT.utf-8',

But the output is the same: h1{font-size:3.5rem}

In this case I think it should be with a “,” and not a “.” if I’m not wrong.

Same with:

'locale' => [
  LC_NUMERIC  => 'it_IT.utf-8'
]

I also tried with de_DE, nothing changes.

German numbers use a comma, so to get a dot instead of a comma for the decimal, you need a country code that by default uses dots, e.g. en_US.

My default uses dots. I wanted to try with de_DE to see if the code works but that didn’t change anything for me, still dots.

Some users that uses my themes have all their CSS calculated with commas… I need to make sure everything is with dots, for the CSS not to break.