Java BigDecimal plus()方法与示例

BigDecimal Class plus()方法 (BigDecimal Class plus() method)

Syntax:

句法:

    public BigDecimal plus();
public BigDecimal plus(MathContext ma_co);

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

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

  • plus() method is used to get the value with (+) representation of this BigDecimal.

    plus()方法用于获取此BigDecimal的(+)表示形式的值。

  • plus(MathContext ma_co) method is used to get the value with (+) representation of this BigDecimal along with rounding based on the given MathContext settings.

    plus(MathContext ma_co)方法用于获取此BigDecimal的(+)表示形式的值,并根据给定的MathContext设置进行舍入。

  • These methods may throw an exception at the time of + representation of an object.

    这些方法在对象的+表示时可能会引发异常。

    ArithmeticException: This exception may throw when the result is not accurate and set the rounding mode "UNNECESSARY".

    ArithmeticException :当结果不正确并且将舍入模式设置为“ UNNECESSARY”时,可能会引发此异常。

  • These are non-static methods and it is accessible with class objects and if we try to access these methods with the class name then we will get an error.

    这些是非静态方法,可通过类对象访问,如果尝试使用类名访问这些方法,则会收到错误消息。

Parameter(s):

参数:

  • In the first case, plus(),

    在第一种情况下, plus()

    • It does not accept any parameter.
  • In the first case, plus(MathContext ma_co),

    在第一种情况下, plus(MathContext ma_co)

    • MathContext ma_co – represents the context setting to use in rounding.
    • MathContext ma_co –表示要舍入的上下文设置。

Return value:

返回值:

In both the cases, the return type of the method is BigDecimal,

在这两种情况下,方法的返回类型均为BigDecimal 。

  • In the first case, it returns the plus value of this BigDecimal.

    在第一种情况下,它返回此BigDecimal的正值。

  • In the second case, it returns the plus value of this BigDecimal. with rounding based on the given context setting.

    在第二种情况下,它返回此BigDecimal的正值。 根据给定的上下文设置进行舍入。

Example:

例:

// Java program to demonstrate the example 
// of plus() method of BigDecimal
import java.math.*;
public class PlusOfBD {
public static void main(String args[]) {
// Initialize two variables val1,
// val2 
String val1 = "-10.30";
int val2 = 4;
// Initialize two BigDecimal objects and
// one MathContext
BigDecimal b_dec1 = new BigDecimal(val1);
BigDecimal b_dec2 = new BigDecimal(val2);
MathContext ma_co = new MathContext(2, RoundingMode.CEILING);
System.out.println("plus(): ");
// returns the plus representation of this BigDecimal
// like (+ b_dec2)
BigDecimal plus = b_dec2.plus();
System.out.println("b_dec2.plus(): " + plus);
System.out.println(" ");
System.out.println("plus(MathContext): ");
// returns the plus representation of this BigDecimal
// (+b_dec1) and return the result based on the given
// context settings
plus = b_dec1.plus(ma_co);
System.out.println("b_dec1.plus(ma_co): " + plus);
}
}

Output

输出量

plus(): 
b_dec2.plus(): 4plus(MathContext): 
b_dec1.plus(ma_co): -10

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

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

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

相关文章

爬虫项目(二)---采集从03月02号以来的世界各国疫情数据

该内容出自黑马程序员教程 采集从03月02号以来的世界各国疫情数据 步骤: Ⅰ,重构项目(一)的代码,以提高扩展性 把功能封装到一个类中每一个小功能变成一个方法通过run方法启动爬虫 import requests import re import json from bs4 impor…

【原创】StreamInsight查询系列(二十)——查询模式之检测间隙事件

上篇文章介绍了查询模式中如何检测异常事件,这篇博文将介绍StreamInsight中如何检测间隙事件。 测试数据准备 为了方便测试查询,我们首先准备一个静态的测试数据源:// 创建数据源,要注意的是4:16和4:30之间存在的事件间隙 var sou…

git 项目过大问题解决

当项目过大时,git clone时会出现error: RPC failed; HTTP curl The requested URL returned error: Gateway Time-out的问题 解决方法很简单,在git clone时加上--depth1即可解决 克隆的项目只包含最近的一次commit的一个分支,体积很小&#x…

java bitset_Java BitSet hashCode()方法及示例

java bitsetBitSet类hashCode()方法 (BitSet Class hashCode() method) hashCode() method is available in java.util package. hashCode()方法在java.util包中可用。 hashCode() method is used to retrieve hash code for this bit set (BitSet). hashCode()方法用于检索此位…

【数据结构基础应用】【查找和排序算法】

代码参考《妙趣横生的算法.C语言实现》 文章目录前言1、顺序查找2、折半查找3、直接插入排序4、选择排序5、冒泡排序6、希尔排序7、快速排序8、堆排序9、排序算法性能比较10、所有算法的code(C语言)前言 本章总结查找和排序算法:顺序查找、折…

MarshalHelper

1 public class MarshalHelper2 {3 /// <summary>4 /// 结构体转byte数组5 /// </summary>6 /// <param name”structObj”>要转换的结构体</param>7 /// <returns>转换后的byte数组</returns&g…

深入浅出SharePoint——InvokeWorkflow的妙用

应用场景&#xff1a;在Parallel Activity中使用InvokeWorkflow来达到间接关闭并行分支的功能。 TestInvokeWorkflow方法用于启动监听工作流。endinvoke方法用户关闭启动的监听工作流实例。 private void TestInvokeWorkflow(object sender, EventArgs e) { SPWeb web SPConte…

爬虫项目(三)---采集最近一日全国各省疫情数据

该内容出自黑马程序员教程 采集最近一日全国各省疫情数据 当然&#xff0c;数据来源仍然是丁香园新型冠状病毒肺炎疫情实时动态首页 url&#xff1a;https://ncov.dxy.cn/ncovh5/view/pneumonia 思路&#xff1a;首先需要先确定全国各省疫情数据的位置 全国各省份的疫情数据…

计算机专业博士后排名,排名丨计算机专业领域TOP10,性价比超高!

原标题&#xff1a;排名丨计算机专业领域TOP10&#xff0c;性价比超高&#xff01;相信各位家长、同学已经看过太多专业的排名&#xff0c;我问过很多理科生将来想学什么专业&#xff0c;听到频率最高的还是计算机专业。似乎大家都知道&#xff0c;学计算机是比较挣钱的&#x…

python set |_Python事件类| set()方法与示例

python set |Python Event.set()方法 (Python Event.set() Method) set() is an inbuilt method of the Event class of the threading module in Python. set()是Python中线程模块的Event类的内置方法。 When the set() method is called, the internal flag of that event c…

js 命名规范

转载于:https://www.cnblogs.com/zjx2011/p/3165043.html

爬虫项目(四)---采集从01月22日以来全国各省疫情数据

采集从03月02日以来全国各省疫情数据 当然&#xff0c;数据来源仍然是丁香园新型冠状病毒肺炎疫情实时动态首页 url&#xff1a;https://ncov.dxy.cn/ncovh5/view/pneumonia 分析 确定01月22日以来全国各省疫情数据的URL 由项目(三)可以获取全国各省疫情数据点击可下载&…

Install PHP and Apache

http://cn.php.net/manual/en/install.unix.apache2.php Install Apache first, then sudo apt-get install libxml2-dev sudo apt-get install libmysqlclient16-dev Then, configure PHP转载于:https://www.cnblogs.com/songsiyao/archive/2011/09/15/2178087.html

纠错码trick和数据压缩trick

纠错码和压缩算法是同一枚硬币的两面。 两者都来自于对冗余的想法。 纠错码被视为向消息或文件中添加冗余的原则性方法。而压缩算法正好相反&#xff0c;他们会从消息或文件中移除冗余。 压缩和纠错并不是彼此抵消的&#xff0c;相反&#xff0c;好的压缩算法会移除抵消冗余&am…

计算机专业理论,计算机专业综合理论.doc

计算机专业综合理论2010年南京市单招班教学调研测试卷(二)计算机专业综合理论命题人&#xff1a;管荣平 陈高峰 戴则萍 吴有俊本试卷分第一卷(单项选择题、判断题)和第二卷(填空题、程序阅读题、编程题和计算作图题)两部分。第一卷1至2页&#xff0c;第二卷3至6页。两卷满分300…

网站上flv,MP4等格式的视频文件播放不出来的解决办法

在做一个网站时&#xff0c;发现视频文件&#xff0c;比如flv&#xff0c;MP4格式在本地可以正常的播放&#xff0c;但是传到了开发机器上&#xff0c;就不行了。播放器的文件地址是对的&#xff0c;就是一直没有反应。 经过长时间的实验&#xff0c;发现问题在与iis的设置问题…

centos6 更新数据源

尝试了很多,还是163源最舒服. 编辑yum配置文件(163源)&#xff1a; #vi /etc/yum.repos.d/CentOS-Base.repo [base] nameCentOS-$releasever - Base mirrorlisthttp://mirrorlist.centos.org/?release$releasever&arch$basearch&repoos #baseurlhttp://mirror.centos…

常用算法总结(穷举法、贪心算法、递归与分治算法、回溯算法、数值概率算法)

博主联系方式&#xff1a; QQ:1540984562 QQ交流群&#xff1a;892023501 群里会有往届的smarters和电赛选手&#xff0c;群里也会不时分享一些有用的资料&#xff0c;有问题可以在群里多问问。 目录1、穷举法2、贪心算法3、递归与分治算法4、回溯算法5、数值概率算法1、穷举法…

struct/class的数据对齐---简单解析

网上教程一大堆&#xff0c;我这边就不再赘述废话了 思路方法&#xff1a; 1&#xff0c;以四个为一组&#xff0c;最终的内存所占结果必须是四的倍数 2&#xff0c;优先考虑四的整数倍&#xff0c;之后再考虑内存空间问题 struct Beyond{int a;char b;short c;}; int mai…

工程师英语和计算机证书查询,点击进入国家硬件维修工程师证书查询网站

工程师证书查询网站人力资源社会保障部指定查询国家职业资格证书的唯一官方网站。涵盖全国各省市、各行业、各央企颁发的证书。电脑硬件维修工程师网上能查看国家工信部硬件维修工程师证书查询网址&#xff1a;http://www.ceiaec.org/index.htm工程师证书编号在网上怎么查询如果…