To round x postion of decimal point, use BigDecimal.setScale().
double requestPerSecond = httpInfo.getRequestPerSencond();
BigDecimal reqPerSec =
new BigDecimal(requestPerSecond).setScale(2,java.math.BigDecimal.ROUND_HALF_UP);
setScale
public BigDecimal setScale(int scale,
int roundingMode)
Returns a BigDecimal whose scale is the specified value, and whose unscaled value is determined by multiplying or dividing this BigDecimal's unscaled value by the appropriate power of ten to maintain its overall value. If the scale is reduced by the operation, the unscaled value must be divided (rather than multiplied), and the value may be changed; in this case, the specified rounding mode is applied to the division.
Note that since BigDecimal objects are immutable, calls of this method do not result in the original object being modified, contrary to the usual convention of having methods named setX mutate field X. Instead, setScale returns an object with the proper scale; the returned object may or may not be newly allocated.
Parameters:
scale - scale of the BigDecimal value to be returned.
roundingMode - The rounding mode to apply.
Returns:
a BigDecimal whose scale is the specified value, and whose unscaled value is determined by multiplying or dividing this BigDecimal's unscaled value by the appropriate power of ten to maintain its overall value.
Throws:
ArithmeticException - scale is negative, or roundingMode==ROUND_UNNECESSARY and the specified scaling operation would require rounding.
IllegalArgumentException - roundingMode does not represent a valid rounding mode.
Visitor :
May 4, 2009
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2009
(33)
-
▼
May
(29)
- Welcom The close() method of ClassLoader in JDK7
- java sources for ojdbc (odjbc14-10.0.2.zip, ojdbc1...
- Notepad with class java file (Jad Usage Tip)
- addShutdownHook() of Runtime class
- JavaFx Programming Reference
- Setting property in svn repository
- JavaOne 2008
- No SqlHandler log4j:ERROR problem
- Thinking about saving error logs in web applicatio...
- Dynamically creating table in ibatis
- checkng(or seeing) oracle jdbc driver(ojdbc.jar) v...
- Deadlock using commons-pool 1.4 and commons-dbcp 1...
- Eclipse Code Style Sample (You can import!)
- MERGE INTO Statement
- Impossible to get merged row count in ibatis. (to ...
- Clone method in Java
- Implementing equals method of collections classes
- Weakness of Java Web Start
- When you apply for developer job..
- G1 garbage collection
- [DBCP] Without given validationQuery, no validatio...
- How to get hostname in http url in Java
- How to get java cpu usage (jvm instance)
- Rounding(Scaling) x postion of decimal point
- Effective Java References
- BCEL in java6
- Good JMX References
- ConcurrentModificationException in java collection...
- How to gain Calendar type to String type in java
-
▼
May
(29)
No comments:
Post a Comment