Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
NumberUtil 添加一些数字常量 fix #693
Browse files Browse the repository at this point in the history
  • Loading branch information
venusdrogon committed Dec 26, 2017
1 parent 26f5257 commit 2091228
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 0 deletions.
112 changes: 112 additions & 0 deletions src/main/java/com/feilong/core/lang/NumberUtil.java
Expand Up @@ -25,6 +25,7 @@
import java.math.RoundingMode;

import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.math.NumberUtils;

import com.feilong.core.NumberPattern;
import com.feilong.core.text.NumberFormatUtil;
Expand Down Expand Up @@ -169,6 +170,117 @@ private NumberUtil(){

//---------------------------------------------------------------

/**
* 一,<code>{@value}</code>.
*
* @since 1.10.7
* @see BigDecimal#ONE
* @see NumberUtils#INTEGER_ONE
*/
public static final int ONE = 1;

/**
* 十,<code>{@value}</code>.
*
* @since 1.10.7
*/
public static final int TEN = 10;

/**
* 百,<code>{@value}</code>.
*
* @since 1.10.7
*/
public static final int HUNDRED = 100;

/**
* 千,<code>{@value}</code>.
*
* @since 1.10.7
*/
public static final int THOUSAND = 1000;

//---------------------------------------------------------------
/**
* 万,<code>{@value}</code>.
*
* @since 1.10.7
*/
public static final int TEN_THOUSAND = 1_0000;

/**
* 十万,<code>{@value}</code>.
*
* @since 1.10.7
*/
public static final int HUNDRED_THOUSAND = 10 * TEN_THOUSAND;

/**
* 百万,<code>{@value}</code>.
*
* @since 1.10.7
*/
public static final int MILLION = 10 * HUNDRED_THOUSAND;

/**
* 千万,<code>{@value}</code>.
*
* @since 1.10.7
*/
public static final int TEN_MILLION = 10 * MILLION;

//---------------------------------------------------------------

/**
* 亿, <code>{@value}</code>.
*
* <h3>说明:</h3>
* <blockquote>
* <ol>
* <li>
* {@link Integer#MAX_VALUE}:21_4748_3647 ,21亿, 注意使用的时候,超过最大值使用long来计算
* </li>
* </ol>
* </blockquote>
*
* @since 1.10.7
*/
public static final int HUNDRED_MILLION = 10 * TEN_MILLION;

/**
* 十亿, <code>{@value}</code>.
*
* <h3>说明:</h3>
* <blockquote>
* <ol>
* <li>
* {@link Integer#MAX_VALUE}:21_4748_3647 ,21亿, 注意使用的时候,超过最大值使用long来计算
* </li>
* </ol>
* </blockquote>
*
* @since 1.10.7
*/
public static final int BILLION = 10 * HUNDRED_MILLION;

/**
* 百亿, <code>{@value}</code>.
*
* <h3>说明:</h3>
* <blockquote>
* <ol>
* <li>
* {@link Integer#MAX_VALUE}:21_4748_3647 ,21亿, 注意使用的时候,超过最大值使用long来计算
* </li>
* </ol>
* </blockquote>
*
* @since 1.10.7
*/
public static final long TEN_BILLION = (long) (BILLION) * 10;

//---------------------------------------------------------------

/**
* 判断第1个数字数字值 <code>one</code> 是不是{@code > } (大于) 第2个数字数字值 <code>two</code>.
*
Expand Down
Expand Up @@ -26,6 +26,8 @@
*/
@RunWith(Suite.class)
@SuiteClasses({
NumberUtilTest.class,

SetScaleTest.class,
SetScaleParameterizedTest.class,
SetScaleRoundingModeParameterizedTest.class,
Expand Down
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2008 feilong
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.feilong.core.lang.numberutiltest;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import com.feilong.core.lang.NumberUtil;

/**
*/
public class NumberUtilTest{

@Test
public void testIsEqualsTestNull1(){
assertEquals(1, NumberUtil.ONE);
assertEquals(10, NumberUtil.TEN);
assertEquals(100, NumberUtil.HUNDRED);
assertEquals(1000, NumberUtil.THOUSAND);

assertEquals(1_0000, NumberUtil.TEN_THOUSAND);
assertEquals(10_0000, NumberUtil.HUNDRED_THOUSAND);
assertEquals(100_0000, NumberUtil.MILLION);
assertEquals(1000_0000, NumberUtil.TEN_MILLION);

assertEquals(1_0000_0000, NumberUtil.HUNDRED_MILLION);
assertEquals(10_0000_0000, NumberUtil.BILLION);
assertEquals(100_0000_0000L, NumberUtil.TEN_BILLION);
}

}

0 comments on commit 2091228

Please sign in to comment.