Copy link to clipboard
Copied
Hello community.
I'm trying to convert string to number with some text in a text field.
Example:
var stringValue = "1099.33";
var numberValue = parseFloat(stringValue);
var formattedValue = numberValue.toLocaleString('de-DE', {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
});
var textValue = "Wir haben " + formattedValue + " EUR.";
In this example, I want to achieve this format Wir haben 1.099,00 EUR. (in this format ###.###,###)
It only works in number fields, but not in text fields. Can anyone help me? I appreciate your help and thank you in advance.
Use this:
var formattedValue = util.printf("%,2.2f", numberValue);
for me has this format worked.
var stringNumber = this.getField("Number").value;
var formattedNumber = util.printf("%.2f", stringNumber).replace(/\./, ',').replace(/(\d)(?=(\d{3})+,)/g, '$1.');
this.getField("Text").value = "You have " + formattedNumber + " EUR ".;
For example: Field value is 1299,67. The result was as excepted:
You have 1.299,67 EUR.
Copy link to clipboard
Copied
Use this:
var formattedValue = util.printf("%,2.2f", numberValue);
Copy link to clipboard
Copied
Thank you for your support 🙂
Copy link to clipboard
Copied
for me has this format worked.
var stringNumber = this.getField("Number").value;
var formattedNumber = util.printf("%.2f", stringNumber).replace(/\./, ',').replace(/(\d)(?=(\d{3})+,)/g, '$1.');
this.getField("Text").value = "You have " + formattedNumber + " EUR ".;
For example: Field value is 1299,67. The result was as excepted:
You have 1.299,67 EUR.