2

I have citation issuing android app that an end user can enter values then 'store' them as defaults, so the next time they go to issue a citation, the default values are prepopulated...

i am able to store a BigDecimal[] to String[] but I'm having the hardest time getting the String[] back into BigDecimal[]

can anyone help me please?

for(int i=0;i<3;i++){
edit.putString(SOMETHING[i], String.valueOf(aSomething.getOtherThing(i)));
}

this works to store it as string but I cant get it back to BigDecimal, i've tried this, among other things:

for(int i=0;i<3;i++){
aSomething.setOtherThing(BigDecimal.valueOf(SOMETHING[i]));
}

thank you!

Yassin Hajaj
  • 21,337
  • 9
  • 51
  • 89
buradd
  • 1,271
  • 1
  • 13
  • 19

1 Answers1

1

You could just simply use

new BigDecimal(str);

In your case it would be

for(int i=0;i<3;i++){
    aSomething.setOtherThing(new BigDecimal(SOMETHING[i]));
}

But you should know that this is not safe and it may throw a NumberFormatException if the value is not a valid representation of a BigDecimal.

Consider checking this Safe String to BigDecimal conversion

Community
  • 1
  • 1
Pablo Matias Gomez
  • 6,614
  • 7
  • 38
  • 72