用于BigDecimal的Java数学库,该库允许空值 [英] java math library for BigDecimal which allows null values

查看:475
本文介绍了用于BigDecimal的Java数学库,该库允许空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个BigDecimal库,其中包含BigDecimal的基本操作,该库允许空值?

Is there a BigDecimal library with the basic operations of BigDecimal which allows null values?

出于数学目的,应将Null视为0.

Null should be treated as 0 for mathematical purpose.

我不想对所有可能的null值进行所有null检查.

I don't want to do all the null checks for possible null values.

您要么永远不允许在数据库,应用程序中使用空值,要么使用new BigDecimal(0)查看和初始化所有内容,或者对每种用法对空值进行空检查.

You either never allow null values in database, application or view and initialize everything with new BigDecimal(0) or perform null checks on every usage for nullable values.

类似的东西:

public static BigDecimal add(final BigDecimal value, final BigDecimal augend)
{
    if (value == null)
        return augend;
    else if (augend == null)
        return value;
    else
        return value.add(augend);
}

public static BigDecimal multiply(final BigDecimal value, final BigDecimal multiplicand)
{
    if (value == null || multiplicand == null)
        return null;

    return value.multiply(multiplicand);
}

推荐答案

保存编码,只是不允许在数据库中使用空值.将默认值设为零.

Save the coding, just don't allow null values in the database. Make the default value zero.

对于new BigDecimal(0):否,请使用BigDecimal.ZERO.

这篇关于用于BigDecimal的Java数学库,该库允许空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆