Java Code Examples for java.math.BigDecimal#ROUND_DOWN

The following examples show how to use java.math.BigDecimal#ROUND_DOWN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MallSetting.java    From java-platform with Apache License 2.0 5 votes vote down vote up
/**
 * 设置精度
 * 
 * @param amount
 *            数值
 * @return 数值
 */
public BigDecimal setScale(BigDecimal amount) {
	if (amount == null) {
		return null;
	}
	int roundingMode;
	if (getPriceRoundType() == RoundType.roundUp) {
		roundingMode = BigDecimal.ROUND_UP;
	} else if (getPriceRoundType() == RoundType.roundDown) {
		roundingMode = BigDecimal.ROUND_DOWN;
	} else {
		roundingMode = BigDecimal.ROUND_HALF_UP;
	}
	return amount.setScale(getPriceScale(), roundingMode);
}
 
Example 2
Source File: WeightBodyCommand.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
private void autoAllocation(BscStructTreeObj treeObj) throws Exception {
	int scale = 2;
	for (VisionVO vision : treeObj.getVisions()) {
		for (int px=0; px<vision.getPerspectives().size(); px++) {
			PerspectiveVO perspective = vision.getPerspectives().get(px);
			int round = BigDecimal.ROUND_DOWN;
			if ( (px+1) == vision.getPerspectives().size() ) {
				round = BigDecimal.ROUND_UP;
			}
			perspective.setWeight( 
					MAX_WEIGHT_VALUE.divide(new BigDecimal(vision.getPerspectives().size()), scale, round) );
			for (int ox=0; ox<perspective.getObjectives().size(); ox++) {
				ObjectiveVO objective = perspective.getObjectives().get(ox);
				round = BigDecimal.ROUND_DOWN;
				if ( (ox+1) == perspective.getObjectives().size() ) {
					round = BigDecimal.ROUND_UP;
				}
				objective.setWeight( 
						MAX_WEIGHT_VALUE.divide(new BigDecimal(perspective.getObjectives().size()), scale, round) );					
				for (int kx=0; kx<objective.getKpis().size(); kx++) {
					KpiVO kpi = objective.getKpis().get(kx);
					round = BigDecimal.ROUND_DOWN;
					if ( (kx+1) == objective.getKpis().size() ) {
						round = BigDecimal.ROUND_UP;
					}						
					kpi.setWeight( 
							MAX_WEIGHT_VALUE.divide(new BigDecimal(objective.getKpis().size()), scale, round) );						
				}
				
			}
		}
	}
}
 
Example 3
Source File: JdkCurrencyProvider.java    From objectlabkit with Apache License 2.0 4 votes vote down vote up
@Override
public int getRounding(String currencyCode) {
    return "JPY".equalsIgnoreCase(currencyCode) ? BigDecimal.ROUND_DOWN : BigDecimal.ROUND_HALF_UP;
}