[Resolved] Using comma as decimal separator in number field
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Hi, we're using number fields in our custom post types. We can enter numbers with a dot as decimal separator, like this: 1.43 In English-speaking countries, the decimal point is usually a small dot (.) In many other countries (e.g. here in Germany), the radix point is a comma (,). How can we achieve that we can enter numbers with a comma instead of a dot? There should be an option for number fields to specify the decimal separator. Maybe there is a filter/hook available to change that? Best regards, Christian
Thank you for contacting us and I'd be happy to assist.
It is recommended to store the unformatted numerical values (for example 1234567.89) as custom field values so that numerical comparisons and arithmetic operations can be performed on them (if and when needed).
You can store the numerical values without the decimal separators in a "number" type custom field and then use a custom shortcode to display the numerical value with decimal separators, on the front end.
( there is no built-in option or filter available for this conversion )
Note: In this example, the Toolset's field shortcode ( [types field='post-number'][/types] ) is used in the new custom shortcode to convert the numerical value from the custom field with slug "post-number" and show the formatted value ( e.g. 1,234,567.89 ).
I hope this helps and please let me know if you need further assistance.
Hi Waqar, thank you for your quick reply. We're already using a similar approach. We are storing the unformatted numerical values in "number" type custom fields and output them through custom shortcodes in the way we need them (so a value like 1.5 becomes 1,5 with a comma instead of a dot). But: We're using a cred form to create new posts via frontend. In this cred form right now users have to enter numerical values with a dot (e.g. 1.5). But they should be able to enter numerical values with a comma as separator (e.g. 1,5) which is then regulary stored as 1.5 in the database. Is there a way to achieve this?
Hi Waqar, thank you for your assistance. Using javascript to resolve this issue doesn't make me completely happy. But it seems to be the only solution right now. In the future it should be possible to chose the separator for the number type custom field, because in the majority of countries worldwide the comma is used as decimal separator instead of a dot. That's why there should be an option for the number type custom field inside toolset rather than manipulating numbers via javascript.
Christian confirmed that the issue was resolved on 2024-02-19 08:21:27.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.