Click here to Skip to main content
15,846,899 members

Comments by priyamtheone (Top 56 by date)

priyamtheone 24-Oct-22 5:18am View    
I understand. min on a number field checks for the value itself and not the number of digits. Thanks for pointing it out.
priyamtheone 14-Mar-22 15:27pm View    
Tested in It validates all the required patterns while dismissing the unrequired ones. Works good in Android Studio too.
priyamtheone 13-Mar-22 11:58am View    
This is what I came up with ^[+|-]?(([0-9]\d{0,2}(,?\d{3})*)(\.\d+)?|(\.\d+))$

I think that allows optional thousand separators and also validates the patterns I mentioned in my original post. By far it looks correct to me.
priyamtheone 12-Mar-22 9:34am View    
That's what I switched to. However, in that case, most programmers suggest not to pass a double or float value to create a BigDecimal, as it may not be able to hold that value precisely. A string should always be used. So I wrote:
String str = "12345678.0123456789";
BigDecimal bd = new BigDecimal(str, MathContext.UNLIMITED);
This time, the value is being held properly with exact scale and precision. Seems like in my scenario, where the fractional part is dynamic, this is how I have to do it. Hold the actual value in a string or BigDecimal, and after performing all math operations, use the held value to check on the number of fractional digits and display the final number accordingly. This is what I could fathom by far. Thank you for pointing out the significant tips.
priyamtheone 11-Mar-22 14:24pm View    
Now I understand the conversion part. There's just one challenge left. In my case, while assigning a value to the variable, how many digits will be there after the decimal is not fixed. It is a dynamic factor. For example, if I assign 12345678.123 to the variable in Activity1, the same 12345678.123 needs to be shown in Activity2. Again, if 12345678.123456 is assigned in Actvity1, the same needs to be shown in Activity2. So you can see the number of digits after the decimal is dynamic. Now, I can convert the scientific notation back to non-scientific form in Activity2 and show it. But before that, how do I identify how many digits after the decimal did the user assign to the variable in Actvity1? Because, right now I'm in Activity2 and the double value that I got from Activity1 is still in scientific notation. That's the only stumbling block. Any help on this issue, please?