Java BigDecimal floatValue()方法与示例
BigDecimal類floatValue()方法 (BigDecimal Class floatValue() method)
- floatValue() method is available in java.math package. - floatValue()方法在java.math包中可用。 
- floatValue() method is used to convert a BigDecimal to a float value and when this BigDecimal magnitude is not in a range of float so it will be changed to Float.POSITIVE_INFINITY or Float.NEGATIVE_INFINITY. - floatValue()方法用于將BigDecimal轉換為float值,并且當此BigDecimal量值不在float范圍內時,它將被更改為Float.POSITIVE_INFINITY或Float.NEGATIVE_INFINITY。 
- floatValue() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error. - floatValue()方法是一種非靜態方法,僅可通過類對象訪問,如果嘗試使用類名訪問該方法,則會收到錯誤消息。 
- floatValue() method does not throw an exception at the time of converting BigDecimal to the float. - 在將BigDecimal轉換為float時, floatValue()方法不會引發異常。 
Syntax:
句法:
public float floatValue();Parameter(s):
參數:
- It does not accept any parameter. - 它不接受任何參數。 
Return value:
返回值:
The return type of this method is float, it returns the float representation of this BigDecimal.
此方法的返回類型為float ,它返回此BigDecimal的float表示形式。
Example:
例:
// Java program to demonstrate the example // of float floatValue() method of BigDecimalimport java.math.*;public class FloatValueOfBD {public static void main(String args[]) {// Initialize two variables first is// of "double" and second is of "String" typedouble val = 1255468.00;String str = "100";// Initialize two BigDecimal objects BigDecimal b_dec1 = new BigDecimal(val);BigDecimal b_dec2 = new BigDecimal(str);// convert this BigDecimal (b_dec1) into// a float, variable named f_convfloat f_conv = b_dec1.floatValue();System.out.println("b_dec1.floatValue(): " + f_conv);// convert this BigDecimal (b_dec2) into// a float, variable named f_convf_conv = b_dec2.floatValue();System.out.println("b_dec2.floatValue(): " + f_conv);} }Output
輸出量
b_dec1.floatValue(): 1255468.0 b_dec2.floatValue(): 100.0翻譯自: https://www.includehelp.com/java/bigdecimal-floatvalue-method-with-example.aspx
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Java BigDecimal floatValue()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 新品索尼8K电视Z8H在画质方面运用的什
- 下一篇: dnf加13冰焰左轮枪
