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 BigDecimal
import java.math.*;
public class FloatValueOfBD {public static void main(String args[]) {// Initialize two variables first is
// of "double" and second is of "String" type
double 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_conv
float f_conv = b_dec1.floatValue();
System.out.println("b_dec1.floatValue(): " + f_conv);
// convert this BigDecimal (b_dec2) into
// a float, variable named f_conv
f_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()方法与示例相关推荐

  1. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  2. java user directory,Java ProcessBuilder directory()方法与示例

    语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...

  3. Java序列化魔术方法及其示例使用

    在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...

  4. catalog java,Java Connection getCatalog()方法与示例

    通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...

  5. filepermission java,Java FilePermission getActions()方法与示例

    FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...

  6. java方法参数Bundle,Java ResourceBundle keySet()方法及示例

    ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...

  7. java exec waitfor,Java Process waitFor()方法与示例

    流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...

  8. java arraylist.add(),Java ArrayList add()方法与示例

    ArrayList类add()方法 语法:public boolean add(T ele); public void add(int indices, T ele);add()方法在java.uti ...

  9. java rollback用法,Java Connection rollBack()方法与示例

    回滚操作将撤消当前事务所做的所有更改,即,如果调用Connection接口的rollBack()方法,则所有修改都将还原到最后一次提交. 您还可以通过将所需的Savepoint对象作为参数传递给此方法 ...

最新文章

  1. (转载) 数组a[]={3,5,2,4,1,8},要求从a中找出所有“和”等于10的子集
  2. 如何把html转换成音频网址,怎么把视频转换成音频 视频转换成mp3
  3. 跑monkey需要安装什么_坤秀为您解析无漆木门安装需要注意什么?
  4. netflix_Netflix的Polynote
  5. 【idea基础知识】常用快捷键整理
  6. C++ 作用域使用规范建议
  7. Linux设备驱动模型-Kset
  8. 狐狸抓老鼠,为何东北向才会成功
  9. Spring源码全解
  10. Charm Bracelet(题目地址链接:https://acs.jxnu.edu.cn/problem/NOIOPJCH02067113)
  11. 2022-08-26 Unity视频播放3——VideoPlayer
  12. 像素坐标转换实际坐标python_像素坐标转世界坐标的计算
  13. 说说“安规”的那些事儿
  14. 12月19日|DevFest 2021 京津冀专场重磅来袭!
  15. 高登学苑-解密携程4.9分的秘诀学习笔记
  16. CommandNotFoundError: Your shell has not been properly configured to use ‘conda deactivate‘.
  17. mmclassification使用步骤与心得/ACCV实验记录
  18. Linkerd实战(2)示例详解
  19. 对账 概念 - 账证核对,账账核对,账实核对,账表核对
  20. moviepy音视频剪辑:颜色相关变换函数blackwhite、colorx、fadein/out、gamma_corr、invert_colors、lum_contrast、mask_color介绍

热门文章

  1. python合并数组输出重复项_python - 不同数组项的所有可能组合[重复] - 堆栈内存溢出...
  2. 手机 服务器 推送消息推送消息,推送信息到手机的pushover使用方法及sample code
  3. 【HBuilder】手机App推送至Apple App Store过程
  4. HTML中直接写js 函数
  5. CSS3与页面布局学习笔记(三)——BFC、定位、浮动、7种垂直居中方法
  6. Azure IoT Hub和Event Hub相关的技术系列-索引篇
  7. 简单的节流函数throttle
  8. elasticsearch-6.0.1安装
  9. Struts2中数据封装方式
  10. (转)求单链表是否有环,环入口和环长