Is it a good idea to hold the numeric values in String
variable in an object (also passing in methods and returning as String) and later while only operating it convert in BigDecimal
and operate?
The intention to use in method signature and pojo's is that operation can be performed in double
or any other type the implementor prefers to
For e.g.
public String operate(String value1, String value2){
BigDecimal val1 = new BigDecimal(value1);
BigDecimal val2 = new BigDecimal(value2);
return val1.multiply(val2).toString();
}
Or it is just an overhead?
Would it affect performance?
It's a bad idea from two standpoints:
Consider this example. An ordinary int
occupies 4 bytes in memory. An int
represented as a String
can occupy up to 72 bytes:
It is 18 (!) times more than a primitive representation of an int
.