Help about Decimal separator

Hello everyone
I keep encountering this issue every time I need floating values. For SilverStripe 3 I use a drop-in replacement for NumericField (named SaneNumericField ) that shaves all the localization crap and leave it with digits and periods. In SilverStripe 4 I manually force every field to HTML5 mode that (at least on firefox) accepts both dots and commas as decimal separators.

What I would like is a way to input numbers with period as decimal separator and without grouping, independently from the locale I’m using. I don’t know what other people do, but here in Italy numbers are usually input from the keypad: commas (the local decimal separator) and dots (grouping separator) are used (if needed) only for presentation.

On github I found many related issues, but I don’t grasp the current state of affairs. Is it possible to have an “international” NumericField right now? Or there is a module implementing it for SilverStripe 4?

In SilverStripe 4, the decimal separator is a dot (.). This is the standard separator for decimal numbers in most countries.

For example, the number 12.34 would be written as “12.34” in SilverStripe.

If you need to display numbers with a different decimal separator, you can use the NumberFormatter class to format the number as needed.

Here’s an example of how you might use the NumberFormatter class to format a number with a comma as the decimal separator:

use NumberFormatter;

$formatter = new NumberFormatter('en_US', NumberFormatter::DECIMAL);
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);
$formatter->setSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL, ',');

$number = 12.34;
$formattedNumber = $formatter->format($number);

// $formattedNumber will be "12,34"

You can read more about the NumberFormatter class in the PHP documentation: PHP: NumberFormatter - Manual

Dude , again , ChatGPT ?

Not. Helping.

1 Like