Java BigDecimal toString()方法与示例

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

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

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

  • toString() method is used to represent string denotation of this BigDecimal with the help of scientific notation when an exponent field is required to denote BigDecimal as String.

    当需要使用指数字段将BigDecimal表示为String时,可以使用toString()方法借助科学表示法来表示此BigDecimal的字符串表示形式。

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

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

  • toString() method does not throw an exception at the time of string representation.

    toString()方法在字符串表示时不会引发异常。

Syntax:

句法:

    public String toString();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of this method is String, it returns string denotation of this BigDecimal.

此方法的返回类型为String ,它返回此BigDecimal的字符串表示形式。

Example:

例:

// Java program to demonstrate the example 
// of String toString() method of BigDecimal
import java.math.*;
public class ToStringOfBD {
public static void main(String args[]) {
// Initializes a variables -  
// String type
String str = "12642E5";
// Initializes a BigDecimal object  
BigDecimal b_dec = new BigDecimal(str);
// represents this BigDecimal b_dec value as
// a String by using the scientific notation
String str_conv = b_dec.toString();
System.out.println("b_dec.toString(): " + str_conv);
}
}

Output

输出量

b_dec.toString(): 1.2642E+9

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

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

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

相关文章

聊聊Spring事务失效的12种场景,太坑了

前言对于从事java开发工作的同学来说,spring的事务肯定再熟悉不过了。在某些业务场景下,如果一个请求中,需要同时写入多张表的数据。为了保证操作的原子性(要么同时成功,要么同时失败),避免数据…

centos6中三台物理机配置nginx+keepalived+lvs

以下只是简单的安装配置,并没有测试这套负载,各种参数大家可以自己测试vip:10.0.50.170lvs server:10.0.50.183real server:10.0.50.184/185183/184/185同步时间,并且安装nginx# ntpdate time.nist.gov# yu…

python整数转换字符串_Python | 将字符串转换为整数列表

python整数转换字符串Given a string with digits and we have to convert the string to its equivalent list of the integers in Python. 给定一个带有数字的字符串,我们必须将该字符串转换为Python中与之等效的整数列表。 Example: 例: Input:str1…

什么是可中断锁?有什么用?怎么实现?

作者 | 王磊来源 | Java中文社群(ID:javacn666)转载请联系授权(微信ID:GG_Stone在 Java 中有两种锁,一种是内置锁 synchronized,一种是显示锁 Lock,其中 Lock 锁是可中断锁&#xff…

android开发,设置listview的高度无效

一般是在item的layout中设置高度 android:layout_height"100dp" 但是发现这样后无效,因此找到解决办法,如下: android:minHeight"100dp"

10个经典又容易被人疏忽的JVM面试题

前言整理了10个经典又容易被疏忽的JVM面试题,谢谢阅读,大家加油哈.1. 对象一定分配在堆中吗?有没有了解逃逸分析技术?「对象一定分配在堆中吗?」 不一定的,JVM通过「逃逸分析」,那些逃不出方法的…

duration java_Java Duration类| ofDays()方法与示例

duration java持续时间Class ofDays()方法 (Duration Class ofDays() method) ofDays() method is available in java.time package. ofDays()方法在java.time包中可用。 ofDays() method is used to represent the given number of days in this Duration. ofDays()方法用于表…

面试官:怎么解决MySQL中的死锁问题?

咱们使用 MySQL 大概率上都会遇到死锁问题,这实在是个令人非常头痛的问题。本文将会对死锁进行相应介绍,对常见的死锁案例进行相关分析与探讨,以及如何去尽可能避免死锁给出一些建议。话不多说,开整!什么是死锁死锁是并…

java的equals方法_Java Duration类| 带示例的equals()方法

java的equals方法持续时间类equals()方法 (Duration Class equals() method) equals() method is available in java.time package. equals()方法在java.time包中可用。 equals() method is used to identifies whether this Duration and the given object are equal or not. …

ubuntu双系统导致进windows花屏

2019独角兽企业重金招聘Python工程师标准>>> 5600U的集成显卡,装了ubuntu的双系统,居然导致进win7的时候花屏,度娘狗哥都不得求解 网上很多解决方法都说在启动时加上nomodeset,发现对ubuntu15没用,且失去了…

stl resize函数_vector :: resize()函数以及C ++ STL中的示例

stl resize函数C vector :: resize()函数 (C vector::resize() function) vector::resize() is a library function of "vector" header, it is used to resize the vector, it accepts the updated number of elements and a default value (optional) and resizes…

工作总结:日志打印的15个建议

前言 日志是快速定位问题的好帮手,是撕逼和甩锅的利器!打印好日志非常重要。今天我们来聊聊日志打印的15个好建议~1. 选择恰当的日志级别 常见的日志级别有5种,分别是error、warn、info、debug、trace。日常开发中,我们需要选择恰…

MFC属性页对话框

属性页对话框 分类 分页和引导 类 CPropertyPage-父亲CDialog类别,所谓的属性页或网页对话框。 CPropertySheet-父类是CWnd,称为属性表单。 一个完整的属性页对话框由一个属性表单多个属性页组成。属性页嵌套在属性表单内。 标签式属性页的创建步骤&…

vector cbegin_vector :: cbegin()函数以及C ++ STL中的示例

vector cbeginC vector :: cbegin()函数 (C vector::cbegin() function) vector::cbegin() is a library function of "vector" header, it is used to get the const iterator pointing to the first element of the vector. vector :: cbegin()是“ vector”头文件…

面试官:ConcurrentHashMap为什么放弃了分段锁?

今天我们来讨论一下一个比较经典的面试题就是 ConcurrentHashMap 为什么放弃使用了分段锁,这个面试题阿粉相信很多人肯定觉得有点头疼,因为很少有人在开发中去研究这块的内容,今天阿粉就来给大家讲一下这个 ConcurrentHashMap 为什么在 JDK8 …

C语言函数指针的应用——自制谐波分析软件

文章目录函数指针简介格式介绍颜色头文件计算机仿真使用说明完整代码部分效果图函数指针简介 如果在一个大型C语言程序中要反复调用函数,而调用的函数又不明确时,函数指针就是一个非常有用的东西。如果你的函数体内可以传递不同的函数,那就非…

PHP5.5四种序列化性能对比

2019独角兽企业重金招聘Python工程师标准>>> 结论: 1、小数组用msgpack,无论空间和性能都最好 2、大数组,考虑空间用igbinary,考虑性能用msgpack json_encode,serialize,igbinary,msgpack四种序列化方式&am…

多线程循环输出abcc++_C ++循环| 查找输出程序| 套装2

多线程循环输出abccProgram 1: 程序1&#xff1a; #include<iostream>using namespace std;int main(){ for(;;){cout<<"Hello ";}return 0;}Output: 输出&#xff1a; Hello Hello .... Infinite loopExplanation: 说明&#xff1a; In the above co…

MyBatis Plus 批量数据插入功能,yyds!

作者 | 王磊来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone最近 Review 小伙伴代码的时候&#xff0c;发现了一个小小的问题&#xff0c;小伙伴竟然在 for 循环中进行了 insert &#xff08;插入&a…

C语言打印彩色字符——以(枚举法+字符串查找)为例展示

文章目录C语言颜色头文件——自制非常简单的调用函数实战演练——一个基础的枚举变量小程序牛刀小试——查找字符小程序C语言颜色头文件——自制非常简单的调用函数 显然&#xff0c;C语言是不会提供打印彩色字符的标准函数&#xff0c;而我们有时候为了强调C语言打印的部分字…