Open JaneSjs opened 1 month ago
Found a possible solution:
public getMaskedValue(src: number): string {
let input: string = src === undefined || src === null ? '' : src.toString();
input = input.replace('.', this.decimalSeparator);
const isValidNumber = !isNaN(parseFloat(input));
if (isValidNumber) {
if (input.includes(this.decimalSeparator)) {
const decimalIndex = input.indexOf(this.decimalSeparator);
const currentPrecision = input.length - decimalIndex - 1;
if (currentPrecision < this.precision) input += '0'.repeat(this.precision - currentPrecision);
} else {
input += this.decimalSeparator + '0'.repeat(this.precision);
}
}
return this.getNumberMaskedValue(input, true);
}
This would be also useful for the following usage scenario: T18699 - How to send decimal number to api from a number type text box?.
T18756 - decimalseparator on the question value https://surveyjs.answerdesk.io/internal/ticket/details/T18756
T18363 - Numeric input mask format https://surveyjs.answerdesk.io/internal/ticket/details/T18363
Usage scenario: a numeric mask allows entering up to two decimal places.
![image](https://github.com/surveyjs/survey-library/assets/22372972/73d7c42a-7d4f-4c85-8447-028b9e503ac4)
However, when a user enters a numeric value without entering a decimal part, the decimal part is not present in a resultant value.![image](https://github.com/surveyjs/survey-library/assets/22372972/32f79aa4-afb8-43e8-87da-82b5d58f0aea)
Introduce an option to format a numeric value according to the decimal part precision (e.g.,
1.00
).