Fortune Telling Collection - Ziwei fortune-telling - How to add and subtract characters and numbers in java
How to add and subtract characters and numbers in java
Convert a string to a number:
There are two ways:
The first kind:
For example; A=" 123 "and b=2, then int num = integer.parseint (a);
Then add and subtract with other numbers;
The second type:
Use bigdecimal num = new bigdecimal (a);
BigDecimal num 2 = new BigDecimal(b);
BigDecimal result = num . add(num 2);
Or subtraction: bigdecimal result = num.subtract (num 2);
Addition, subtraction, multiplication and division can be realized by calling various methods of BigDecimal.
Comparison of two methods:
The first one can only realize integer conversion;
The second one can realize any type of conversion with high calculation accuracy.
- Previous article:A Brief Introduction to Yin Yelai's Novels
- Next article:Osmanthus fragrans and purple tiger searching for skin
- Related articles
- Send Wei Zi Stump Video.
- Weizi Garden in Zhenjiang
- Video of Ge You and Wei Zi.
- What routes are there at Foshan Shadi Airport?
- Hu Ziwei's hometown
- What about Xi 'an Greentown Property?
- What is the relationship between Wei Zierkang and Wei Zi?
- Jinsuo Wei Zi meet.
- Classical literary sentences
- How many kilometers is it from Xunhua to Baizhuang?