本文整理汇总了Java中java.math.BigDecimal.floatValue方法的典型用法代码示例。如果您正苦于以下问题:Java BigDecimal.floatValue方法的具体用法?Java BigDecimal.floatValue怎么用?Java BigDecimal.floatValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.math.BigDecimal
的用法示例。
在下文中一共展示了BigDecimal.floatValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateAcceleration
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Update the acceleration using the velocity and time elapsed.
*
* @param location new location
*/
synchronized private void updateAcceleration(Location location) {
if (location.hasSpeed()) {
if (!hasVelocity) {
mVelocity = location.getSpeed();
mTime = System.currentTimeMillis();
hasVelocity = true;
} else {
float velocity = location.getSpeed();
long currentTime = System.currentTimeMillis();
float acceleration = (velocity - mVelocity) / (currentTime - mTime) * 1000;
BigDecimal accelerationRounded = new BigDecimal(acceleration).setScale(2, BigDecimal.ROUND_HALF_UP);
mAcceleration = accelerationRounded.floatValue();
mVelocity = velocity;
mTime = currentTime;
hasAcceleration = true;
}
}
}
示例2: RotationRequest
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Create a new rotation request.
*
* @param rotation Rotation in degrees. Must be between 0 and 360
* @param mirror Mirror the image when rotating
* @throws IllegalArgumentException if the rotation degrees are not between 0 and 360
*/
public RotationRequest(BigDecimal rotation, boolean mirror) throws IllegalArgumentException {
if (rotation.floatValue() < 0 || rotation.floatValue() > 360) {
throw new IllegalArgumentException("Rotation must be between 0 and 360");
}
this.rotation = rotation;
this.mirror = mirror;
}
示例3: round
import java.math.BigDecimal; //导入方法依赖的package包/类
public static float round(float d, int decimalPlace) {
BigDecimal bd = new BigDecimal(Float.toString(d));
bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
return bd.floatValue();
}
示例4: analogStickCalc
import java.math.BigDecimal; //导入方法依赖的package包/类
public void analogStickCalc(int x, int y, int[] x_calc, int[] y_calc) {
float xF, yF, hori, vert;
float deadZoneCenter = 0.15f;
float deadZoneOuter = 0.10f;
x = Math.max(x_calc[0], Math.min(x_calc[2], x));
y = Math.max(y_calc[0], Math.min(y_calc[2], y));
if (x >= x_calc[1]) {
xF = (float) (x - x_calc[1]) / (float) (x_calc[2] - x_calc[1]);
} else {
xF = -((float) (x - x_calc[1]) / (float) (x_calc[0] - x_calc[1]));
}
if (y >= y_calc[1]) {
yF = (float) (y - y_calc[1]) / (float) (y_calc[2] - y_calc[1]);
} else {
yF = -((float) (y - y_calc[1]) / (float) (y_calc[0] - y_calc[1]));
}
float mag = (float) Math.sqrt(xF * xF + yF * yF);
if (mag > deadZoneCenter) {
// scale such that output magnitude is in the range [0.0f, 1.0f]
float legalRange = 1.0f - deadZoneOuter - deadZoneCenter;
float normalizedMag = Math.min(1.0f, (mag - deadZoneCenter) / legalRange);
float scale = normalizedMag / mag;
hori = xF * scale;
vert = yF * scale;
} else {
// stick is in the inner dead zone
hori = 0.0f;
vert = 0.0f;
}
BigDecimal bdHori = new BigDecimal(hori);
bdHori = bdHori.setScale(2, RoundingMode.HALF_EVEN);
BigDecimal bdVert = new BigDecimal(vert);
bdVert = bdVert.setScale(2, RoundingMode.HALF_EVEN);
horizontal = bdHori.floatValue();
vertical = bdVert.floatValue();
}
示例5: getBaseValue
import java.math.BigDecimal; //导入方法依赖的package包/类
private double getBaseValue(SRVMBidder bidder, Band band) {
Preconditions.checkArgument(bidder.getBaseValues().containsKey(band.getName()));
BigDecimal value = bidder.getBaseValues().get(band.getName());
return value.floatValue();
}
示例6: getIntrabandSynergyFactor
import java.math.BigDecimal; //导入方法依赖的package包/类
private double getIntrabandSynergyFactor(SRVMBidder bidder, Band band) {
Preconditions.checkArgument(bidder.getIntrabandSynergyFactors().containsKey(band.getName()));
BigDecimal value = bidder.getIntrabandSynergyFactors().get(band.getName());
return value.floatValue();
}
示例7: round
import java.math.BigDecimal; //导入方法依赖的package包/类
public static float round(double d, int decimalPlace) {
BigDecimal bd = new BigDecimal(Double.toString(d));
bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
return bd.floatValue();
}
示例8: getReoundedMeasure
import java.math.BigDecimal; //导入方法依赖的package包/类
private float getReoundedMeasure(Float measure, int decimal) {
BigDecimal bd = new BigDecimal(Float.toString(measure));
bd = bd.setScale(decimal, BigDecimal.ROUND_HALF_UP);
return bd.floatValue();
}
示例9: getReoundedMeasure
import java.math.BigDecimal; //导入方法依赖的package包/类
private float getReoundedMeasure(double measure, int decimal) {
BigDecimal bd = new BigDecimal(Double.toString(measure));
bd = bd.setScale(decimal, BigDecimal.ROUND_HALF_UP);
return bd.floatValue();
}
示例10: Rounding
import java.math.BigDecimal; //导入方法依赖的package包/类
private static double Rounding(double d) {
BigDecimal bd = new BigDecimal(d);
bd.setScale(1, RoundingMode.HALF_UP);
return bd.floatValue();
}
示例11: round
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Rounds the {@code inputValue} to specified number of digits to the right of the decimal point.
* This function rounds the number depending on the "{@code numberOfDigits} + 1" digit.
*
* @param inputValue the double value to be rounded
* @param numberOfDigits the number of digits to round the {@code inputValue}
* @return rounded {@code inputValue} value
*/
public static Float round(Float inputValue, int numberOfDigits) {
if (inputValue == null)
return null;
BigDecimal bigDecimal = new BigDecimal(inputValue);
bigDecimal = bigDecimal.setScale(numberOfDigits, RoundingMode.HALF_UP);
return bigDecimal.floatValue();
}
示例12: roundUp
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Rounds the {@code inputValue} to specified number of digits to the right of the decimal point.
* This function always rounds up the number irrespective of the "{@code numberOfDigits} + 1" digit.
*
* @param inputValue the float value to be rounded up
* @param numberOfDigits the number of digits to round up the {@code inputValue}
* @return rounded up {@code inputValue} value
*/
public static Float roundUp(Float inputValue, int numberOfDigits) {
if (inputValue == null)
return null;
BigDecimal bigDecimal = new BigDecimal(inputValue);
bigDecimal = bigDecimal.setScale(numberOfDigits, BigDecimal.ROUND_UP);
return bigDecimal.floatValue();
}
示例13: roundDown
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Rounds the {@code inputValue} to specified number of digits to the right of the decimal point.
* This function always rounds down the number irrespective of the "{@code numberOfDigits} + 1" digit.
*
* @param inputValue the float value to be rounded down
* @param numberOfDigits the number of digits to round down the {@code inputValue}
* @return rounded down {@code inputValue} value
*/
public static Float roundDown(Float inputValue, int numberOfDigits) {
if (inputValue == null)
return null;
BigDecimal bigDecimal = new BigDecimal(inputValue);
bigDecimal = bigDecimal.setScale(numberOfDigits, BigDecimal.ROUND_DOWN);
return bigDecimal.floatValue();
}
示例14: truncate
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Truncates the {@code inputValue} to specified number of digits to the right of the decimal point.
* If {@code numberOfDigits} is greater than the number of digits to the right of {@code input} then the
* function returns {@code input} value. It does not add trailing zeros.
*
* @param inputValue the float value to be truncated
* @param numberOfDigits the number of digits to truncate to the right of the decimal point
* @return truncated {@code input} value
*/
public static Float truncate(Float inputValue, int numberOfDigits) {
if (inputValue == null)
return null;
BigDecimal bigDecimal = new BigDecimal(inputValue);
BigDecimal roundedWithScale = bigDecimal.setScale(numberOfDigits, RoundingMode.DOWN).stripTrailingZeros();
return roundedWithScale.floatValue();
}
示例15: getFloat
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Returns the value of the specified attribute in the current item as a
* <code>float</code>.
*
* @see #isNull(String) #isNull(String) to check if the attribute value is
* null.
* @see #isPresent(String) #isPresent(String) to check if the attribute
* value is present.
*
* @throws NumberFormatException
* if the attribute value is null or not a valid representation
* of a {@code BigDecimal}.
*/
public float getFloat(String attrName) {
BigDecimal bd = getNumber(attrName);
if (bd == null) {
throw new NumberFormatException("value of " + attrName + " is null");
}
return bd.floatValue();
}