當前位置: 首頁>>代碼示例>>Java>>正文


Java BigDecimal.floatValue方法代碼示例

本文整理匯總了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;
        }
    }
}
 
開發者ID:w86763777,項目名稱:BikeLine,代碼行數:25,代碼來源:GPSService.java

示例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;
}
 
開發者ID:dbmdz,項目名稱:iiif-apis,代碼行數:15,代碼來源:RotationRequest.java

示例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();
}
 
開發者ID:Dentacoin,項目名稱:aftercare-app-android,代碼行數:6,代碼來源:DCUtils.java

示例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();
}
 
開發者ID:elgoupil,項目名稱:joyconLib,代碼行數:43,代碼來源:JoyconStickCalc.java

示例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();
}
 
開發者ID:spectrumauctions,項目名稱:sats-opt,代碼行數:6,代碼來源:SRVMBidderPartialMIP.java

示例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();
}
 
開發者ID:spectrumauctions,項目名稱:sats-opt,代碼行數:6,代碼來源:SRVMBidderPartialMIP.java

示例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();
}
 
開發者ID:redmyers,項目名稱:484_P7_1-Java,代碼行數:6,代碼來源:Utils.java

示例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();
}
 
開發者ID:geowe,項目名稱:sig-seguimiento-vehiculos,代碼行數:6,代碼來源:MeasureAreaTool.java

示例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();
}
 
開發者ID:geowe,項目名稱:sig-seguimiento-vehiculos,代碼行數:6,代碼來源:RouteVehicleTool.java

示例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();
}
 
開發者ID:miLLlulei,項目名稱:Accessibility,代碼行數:6,代碼來源:FileUtils.java

示例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();
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:16,代碼來源:NumericFunctions.java

示例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();
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:16,代碼來源:NumericFunctions.java

示例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();
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:16,代碼來源:NumericFunctions.java

示例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();
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:17,代碼來源:NumericFunctions.java

示例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();
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:21,代碼來源:Item.java


注:本文中的java.math.BigDecimal.floatValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。