开发者

How do I pass kilogram, gram to a kilogram converter and obtain the result in grams

开发者 https://www.devze.com 2023-01-25 18:02 出处:网络
How do I pass kilogram, gram to a kilogram converter and obtain the result in grams (e.g. 5 kg 500 grams = 5500 grams)

How do I pass kilogram, gram to a kilogram converter and obtain the result in grams (e.g. 5 kg 500 grams = 5500 grams)

How to do this using javax.measure.* Refer over here

Note: I开发者_运维技巧 need the solution only based on the above packages and not some generic solution


It's a rather cumbersome API, but something like this?

int grams = Measure.valueOf(5, SI.KILOGRAM).intValue(SI.GRAM) + 
            Measure.valueOf(500, SI.GRAM).intValue(SI.GRAM);

There's probably a more formal method for arithmetic on Measure values, but I can't find it.

0

精彩评论

暂无评论...
验证码 换一张
取 消