简体   繁体   中英

Big Numbers handling in groovy + Jmeter + java

I have a question about big numbers in groovy, I write at script that call to DB and put budget value in variable called toub_start_budget, the value stored is 2570000000. since I want to do arithmetic operation I created another variable called toub_budget and put in it the value of the first variable as float. The problem is that the new variable not saved the data as float but as a number as 2.56999987E9. and the arithmetic that I do are wrong, for example divide by 1000000, will bring 2569.9 and not the accurate results 2570 (accuracy is important). can someone please advise how to handle big numbers, with arithmetic? regards

在此处输入图片说明

在此处输入图片说明

Do not use float , it is by definition inaccurate. If you need to do accurate calculations and arbitrary big numbers, use BigDecimal . If you use Groovy, then just do the calculation, Groovy will automatically use BigDecimal when appropriate as you can see by executing (2570000000 / 1000).getClass() and (2570000000 / 1001).getClass()

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM