I would like to know how to save a bigDecimal data to a file.
After searching the stack overflow, I noticed that if you are dealing with financial calculations, you need to use BigDecimal and not double. To follow up on that, say for example, a Tip Calculator, Is it recommended to use double or BigDecimal?
If we use BigDecimal, how would save the data to a file.
I want to write the BigDecimal data to a file using FileUtils library.
Thanks for your help!
You have 2 choices: Serialize the object and save it that way (Use ObjectOutputStream), or you could convert it to a String (this is what I'd do) and save the serialized string. BigDecimal has a string constructor, so it is easy to go back and forth (BigDecimal/String). ObjectOutputStream seems to be incompatible with FileUtils without a serious workaround, so you might want to do the string conversion method
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.