How do I concatenate two numbers in BigDecimal? I have this example:
BigDecimal d = BigDecimal.valueOf(5.5);
int a = 1;
int b = 11;
and I want to concat d.a and d.b to generate 5.501 and 5.511 in same length without using divide or other operation!
Is there an instruction with BigDecimal to make it directly ?
Use the fact that
BigDecimalcan parse stings, and that strings are easy to concatenate.Output:
The length is hard coded in
%02d. You could generate the format string dynamically by inspectingString.valueOf(a).length().