Skip to main content
cmvarga5
Known Participant
August 8, 2024
Answered

1000 separator for French numbers

  • August 8, 2024
  • 2 replies
  • 1728 views

I am working on a French form that has a table with several $ fields. The options for number formatting doesn't include the space as a 1000 separator, but it includes the comma as a decimal. Is there a way to get that 1000 separator (space)?

 

I found this script on another website:

var x = Number(event.value).toFixed(2);
event.value = x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "); // use space as thousand separator

 

But that script keeps showing up as 1,#R if I put "1000", but the actual number will show up if I click on the text field "1 000,00"

 

Can someone please help?

This topic has been closed for replies.
Correct answer try67

Here's the adjusted code:

 

var x = Number(event.value).toFixed(2);
event.value = x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ").replace(/\./g, ",");

// use space as thousand separator, and a comma as the decimal separator

2 replies

JR Boulay
Community Expert
Community Expert
October 24, 2024

See this sample, the keystroke script only allows numbers to be entered, and the other script applies the French format or hide the zero.

Acrobate du PDF, InDesigner et Photoshopographe
cmvarga5
cmvarga5Author
Known Participant
October 25, 2024

But what if I need to add decimal values? It won't let me type a period or a comma.

try67
Community Expert
Community Expert
August 8, 2024

I used that code as the custom Format script of a field, and it converts "1000" to "1 000.00" correctly. However, it doesn't use a comma as the decimal separator, but I'm sure that can be adjusted.

The fact it reverts back to the original value when you click into the field is correct, too, as a Format script only changes the way a value is displayed, not the actual value. This is especially desired if you want to use that value for other calculations, as it would have to be in a format that the application can identify as a number.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 8, 2024

Here's the adjusted code:

 

var x = Number(event.value).toFixed(2);
event.value = x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ").replace(/\./g, ",");

// use space as thousand separator, and a comma as the decimal separator

cmvarga5
cmvarga5Author
Known Participant
August 15, 2024

Thank you so much!!!