1. Problem Identification:
The current implementation in SliderSet.SetTarget() calculates the input field's characterLimit using:
Mathf.FloorToInt(1f + Mathf.Log10(this.numberInput.maxValue + (float)this.numberInput.decimalPlaces))
This formula is mathematically flawed because:
Adding decimalPlaces directly to maxValue has no logical basis (e.g., 10000 + 2 = 10002 yields nearly identical Log10 results).
The calculation ignores the actual character requirements for:
The decimal point (.).
Decimal digits (which should scale independently of the integer part).
2. Consequences:
Underestimated character limits when:
maxValue is large (e.g., 1e6) and decimalPlaces > 0.
decimalPlaces is high (e.g., 6), causing truncation of valid inputs like "1000000.000000".
UI/UX issues: Users may be unable to enter or view full values despite them being within the allowed range.
3. Expected Behavior:
The characterLimit should accommodate:
All integer digits of maxValue.
The decimal point (if decimalPlaces > 0).
All decimal digits (per decimalPlaces).
4. Proposed Solution:
Replace the current formula with:
int integerDigits = (maxValue == 0) ? 1 : Mathf.FloorToInt(Mathf.Log10(maxValue)) + 1; int decimalChars = (decimalPlaces > 0) ? 1 + decimalPlaces : 0; // 1 for '.' this.numberInput.field.characterLimit = integerDigits + decimalChars;
-
There are no comments to display.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now