Skip to main content
Inspiring
June 26, 2024
Answered

Comma is treated as decimal

  • June 26, 2024
  • 1 reply
  • 802 views

I am working on a document where the user enters an average service package value into a field. Currently, the field has some placeholder text to give additional context, set with a custom format script.

if (!event.value) {

event.value = "How much is your average client paying to work with you?";
event.target.display = display.noPrint;

} else {

event.target.display = display.visible;
event.value = util.printf("$%,02.0f",event.value);
}

If I enter a value without a comma separating the thousands place from the hundreds place, everything works as expected. If I enter the value using a comma, it is treated as a decimal point.

 

I'm flummoxed as to how to specify the number format for the input while still having custom calculation code to display the placeholder text.

 

Any help would be so greatly appreciated!

This topic has been closed for replies.
Correct answer try67

You can't use both types of decimal separators in a single pattern. How is the script supposed to know if the user entered a thousands separator, or a decimal point?

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 26, 2024

You can't use both types of decimal separators in a single pattern. How is the script supposed to know if the user entered a thousands separator, or a decimal point?

Inspiring
June 27, 2024

Thanks for your response, try67, but I'm afraid I still don't follow. I have been able to use the util.printf() function before to specify number of decimal points and commas (though I can't recall if I tested people entering values with commas in those) and it does display whole numbers and/or calculations with decimal points correctly.

 

What is a better way to go about this? I'd prefer the result to be a whole number in this case, no decimal points, with a comma separation after the thousands place.

 

If I didn't have placeholder text, I'd be able to set the number format directly, but the placeholder text is within the custom format area, so that path isn't available. Though I can see from another forum post that you have recommended doing placeholder text in the On Focus/On Blur events. I have experimented with both that method and the custom format script previously, though I can't recall why I went with the format instead (there was definitely a reason, but it was a few years ago and I've done it as a custom format ever since).

Inspiring
June 27, 2024

Ah, upon experimenting with the On Focus/On Blur method, I can't use placeholder text when the field is formatted as a number. So it would seem I would need to have the correct script to place inside the custom format instead. (Unless it is a...custom keystroke script situation, which I admit I do get lost on when and how to use that.)