BigDecimal类stripTrailingZeros()方法 (BigDecimal Class stripTrailingZeros() method)

  • stripTrailingZeros() method is available in java.math package.

    stripTrailingZeros()方法在java.math包中可用。

  • stripTrailingZeros() method is used to get a BigDecimal that is equivalent to this BigDecimal but without any Trailing zeros.

    stripTrailingZeros()方法用于获取与该BigDecimal等效但没有任何尾随零的BigDecimal。

  • stripTrailingZeros() 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.

    stripTrailingZeros()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • stripTrailingZeros() method does not throw an exception at the time of trailing zeros.

    在尾随零时, stripTrailingZeros()方法不会引发异常。

Syntax:

句法:

    public BigDecimal stripTrailingZeros();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of this method is BigDecimal, it returns a BigDecimal that is similar to this BigDecimal but without any trailing zeros.

该方法的返回类型为BigDecimal ,它返回一个与该BigDecimal相似的BigDecimal,但没有任何尾随零。

Example:

例:

// Java program to demonstrate the example
// of BigDecimal stripTrailingZeros() method of BigDecimal
import java.math.*;
public class StripTrailingZerosOfBD {public static void main(String args[]) {// Initialize two variables - double and
// String type
double val = 1234521.000;
String str = "1211000";
// Initialize three BigDecimal objects
BigDecimal b_dec1 = new BigDecimal(val);
BigDecimal b_dec2 = new BigDecimal(str);
// returns this BigDecimal (b_dec1) but
// with removed any trailing zeros i.e. 1234521.000
// it returns 1234521 because traling zeros will be removed
BigDecimal bd = b_dec1.stripTrailingZeros();
System.out.println("b_dec1.stripTrailingZeros(): " + bd);
// returns this BigDecimal (b_dec2) but
// with removed any trailing zeros i.e. 1211000
// it returns 1.211E+6 and after decimal represent 6 digits
bd = b_dec2.stripTrailingZeros();
System.out.println("b_dec2.stripTrailingZeros(): " + bd);
}
}

Output

输出量

b_dec1.stripTrailingZeros(): 1234521
b_dec2.stripTrailingZeros(): 1.211E+6

翻译自: https://www.includehelp.com/java/bigdecimal-striptrailingzeros-method-with-example.aspx

Java BigDecimal stripTrailingZeros()方法与示例相关推荐

  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. 一个基于组件的动态对象系统
  2. Rails 添加新的运行环境
  3. etcd — 操作手册
  4. 学习笔记(五)——JavaScript(二)
  5. wxWidgets:异形窗示例
  6. HDU4324(强连通的Tarjan算法)
  7. Unity中BVH骨骼动画驱动的可视化理论与实现
  8. Unity3D Shader入门指南(二)
  9. Elasticsearch Reference [6.7] » Modules » Network Settings
  10. leetcode374. 猜数字大小(二分法)
  11. Java笔记-RabbitMQ中生产者端confirm模式
  12. uboot之fastboot烧录镜像
  13. libevent book——event | Gaccob的博客
  14. Docker hello workd
  15. 10个开源且优秀的后台管理系统UI面板
  16. 华为mate10手机听筒测试软件,华为mate 10功能说:这几个设置,让你通话体验直线上升,简直了!...
  17. Java 重写 多态性_Java 学习(12):重写(Override)与重载(Overload) 多态
  18. 解决UE4官方文档C++API查询慢问题
  19. WDS+ADK+MDT部署Windows pxe
  20. C++ cin.get用法(详解版)

热门文章

  1. Metaspliot 控制终端利用Samba漏洞渗透
  2. 单片机备用电池供电电路_第五节(重排) 电子入门 复位电路
  3. 通过url,获取html内容,并解析,如何使用 JavaScript 解析 URL
  4. vue中使用Ueditor编辑器 -- 1
  5. 关于form标签,你该知道
  6. vue class绑定方式
  7. angularjs封装bootstrap官网的时间插件datetimepicker
  8. jQuery下如何使用Json传递数据
  9. mockJs文档(一)
  10. hdu5111 树链剖分,主席树