Java BigDecimal stripTrailingZeros()方法与示例

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/379819.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

外部中断---STM32F1

外部中断概述 STM32的中断控制器支持19个外部中断/事件请求: 线0-15:对应外部IO口的输入中断线16:连接到PVD输出线17:连接到RTC闹钟事件线18:连接到USB唤醒事件 STM32每个IO口都有可以作为外部中断输入,…

转:点9图

关于”点九” 转:http://mux.baidu.com/?p1506“点九”是andriod平台的应用软件开发里的一种特殊的图片形式,文件扩展名为:.9.png 智能手机中有自动横屏的功能,同一幅界面会在随着手机(或平板电脑)中的方向传感器的参数不同而改变显示的方向…

Python HTMLCalendar类| 带实例的formatyear()方法

Python HTMLCalendar.formatyear()方法 (Python HTMLCalendar.formatyear() Method) formatyear() method is an inbuilt method of the HTMLCalendar class of calendar module in Python. It works on HTMLCalendar class object and returns an HTML table consisting of th…

2009中国企业家新春联谊会

2009中国企业家新春联谊会——把握当前机遇,笑对经济危机,畅饮将帅美酒尊敬的嘉宾:当前,国际形势正在发生深刻而复杂的变化,由美国次贷危机引发的全球经济危机已经愈演愈烈,美国前五大投资银行有3家宣告破产…

串口通信的基本原理----STM32

串口通信基本原理 1. 处理器与外部设置通信的基本方式 并行通信:数据各个位同时传输串行通信:数据按位顺序传输 在串行通信中,按照数据的传输方向,又分为: 单工:数据传输只支持在一个方向传输半双工&am…

java获取vm运行参数_如何获取在Java中运行Java VM的版本?

java获取vm运行参数To get the version of running VM (Virtual Machine) in Java, we use the getProperties() method, which is defined in System class, while calling the method, we need to pass the property name to get the version of running Java VM. 要获取Java…

Spring MVC+Ant+Tomcat+Eclipse最简单的demo

第一步是Java的Web环境搭建,下载Eclipse(或者更好的但收费的IDE-IntelliJ Idea,和Resharper一家公司出的),下载Tomcat,下载JDK,下载Spring,注意安装Tomcat的时候配置一下管理员账号和…

MySQL的环境变量配置详细步骤

1.下载MySQL 例如下载:mysql-installer-community-5.5.60.1 我以这个版本为例 2.右击->我的电脑->属性 3. 4.找到在 系统变量 中找到 Path 5.找MySql的bin目录(每个人的电脑上这个文件的位置应该是差不多的,找到之后复制下来&#x…

转帖:强命名程序集(Strong Name Assembly)的概念

强命名程序集(Strong Name Assembly)的概念因为不同的公司可能会开发出有相同名字的程序集来,如果这些程序集都被复制到同一 个相同的目录下,最后一个安装的程序集将会代替前面的程序集。这就是著名的Windows “DLL Hell”出现的原…

串口发送通信---UART发送---STM32F4实现

串口发送程序配置过程(HAL库) 初始化串口相关参数,使能串口 HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart)该函数的参数是串口的基址,在stm32f429xx.h文件中,定义了8个UART_HandleTypeDef的值&#x…

开源软件 许可证密钥_自由和开源软件-1中的重要许可证

开源软件 许可证密钥Its important to take note that there are no good or bad licenses and that no license is superior to another. Anybody can make an open-source license that suits their extravagant, which is the explanation that there are such huge numbers…

串口接收中断配置过程---STM32F4--HAL

串口接收中断程序配置过程(HAL) 初始化相关参数,使能串口: HAL_UART_Init();该函数的参数是串口的基址,在stm32f429xx.h文件中,定义了8个UART_HandleTypeDef的值,分别是USART1、USART2、USART…

electron 切换至esm

前言 好消息,经过不知道多少年的讨论。 electron28.0.0开始(23.08.31),默认支持esm了。 see https://github.com/electron/electron/issues/21457 使用方法 升级至electron^28.0.0简单地在package.json中添加"type":…

javascript运算符_JavaScript中!=或!==运算符之间的区别

javascript运算符We can perceive the differences between these two operators as the same difference that occurs between double equalsTo () and triple equalsTo () operators. We already know that the (!) not-operator used along with () operator is used to che…

实训09.09:简单的彩票系统(机选多注)

package wsq; import java.util.Random; import java.util.Scanner;//机选多注 public class MoreCaiPiao {public static void main(String[] args) {// 定义二维数组 存储多注彩票int[][] numArray new int[5][7];/** 二维数组中 未赋值之前的元素值都为0 { {0,0,0,0,0,0,0}…

项目组的激励策略

我们经常会采取一奖励措施,来激发大家工作的积极性,从而达到提高工作效率的目的。那么我们应该对项目组中的那些类型的人实施激励呢?项目的实践过程中,笔者认为有两类人需要给予正面的奖励。一,能够主动思考&#xff0…

zk中的Datebox中得到Timestamp

String formatDate sdf.format(datebox.getValue()); para.setCreate_time(Timestamp.valueOf(formatDate)); 转载于:https://www.cnblogs.com/avenxia/archive/2012/04/15/2450052.html

定时器--STM32f4--HAL

基本概念 STM32中有三种定时器,高级定时器,通用定时器,基本定时器,具体如下图: 发生如下事件将产生中断/DMA 更新:计数器向上溢出/向下溢出,计数器初始化触发事件:计数器启动、停…

实训09.09:简单的彩票系统(自选多注)

package wsq; import java.util.Scanner; public class CustomCaipiao {public static void main(String[] args) {/** 用户自选彩票数字: 1.使用scanner来输入彩票号码! 2.直接写成自选多注,注数由用户输入决定;* 3.红球值1-33,不重复;蓝球值1-16;*/// 定义二维数组 存储所有的…

c ++查找字符串_C ++类和对象| 查找输出程序| 套装4

c 查找字符串Program 1: 程序1&#xff1a; #include <iostream>using namespace std;class Sample {int X;int* const PTR &X;public:void set(int x);void print();};void Sample::set(int x){*PTR x;}void Sample::print(){cout << *PTR - EOF << …