com.feilong.core.NumberPattern Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of feilong Show documentation
Show all versions of feilong Show documentation
feilong is a suite of core and expanded libraries that include utility classes, http, excel,cvs, io classes, and much much more.
/*
* 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;
import java.text.DecimalFormat;
/**
* 常用的数字模式.
*
* 常用数字格式:
*
*
*
*
*
* Symbol
* Location
* Localized?
* Meaning
*
*
*
* 0
* Number
* Yes
* 每一个0表示一位阿拉伯数字,如果该位不存在,则显示0
* 如果对应位置上没有数字,则用零代替
*
*
*
* #
* Number
* Yes
* 每一个#表示一位阿拉伯数字,如果该位不存在,则不显示
* 如果对应位置上没有数字,则保持原样(不用补);如果最前、后为0,则保持为空.
*
*
*
* .
* Number
* Yes
* 小数点分隔符或货币的小数分隔符
*
*
*
* -
* Number
* Yes
* Minus sign 代表负号
*
*
*
* ,
* Number
* Yes
* Grouping separator分组分隔符
*
*
*
* E
* Number
* Yes
* Separates mantissa and exponent in scientific notation. Need not be quoted in prefix or suffix. 分隔科学计数法中的尾数和指数
*
*
*
* ;
* Subpattern boundary
* Yes
* Separates positive and negative subpatterns
*
*
*
* %
* Prefix or suffix
* Yes
* 数字乘以100并显示为百分数
*
*
*
* \u2030
* Prefix or suffix
* Yes
* 乘以1000并显示为千分数
*
*
*
* ¤
(\u00A4
)
* Prefix or suffix
* No
* Currency sign, replaced by currency symbol. If doubled, replaced by international currency symbol. If present in a pattern, the
* monetary decimal separator is used instead of the decimal separator.
* 货币记号,由货币号替换.
* 如果两个同时出现,则用国际货币符号替换; 如果出现在某个模式中,则使用货币小数分隔符,而不使用小数分隔符
*
*
*
* '
* Prefix or suffix
* No
* 用于在前缀或后缀中为特殊字符加引号, 例如 "'#'#" 将 123 格式化为 "#123".
* 要创建单引号本身,则连续使用两个单引号,例如"# o''clock"
*
*
*
*
* @author feilong
* @see DecimalFormat
* @since 1.0.2
*/
public final class NumberPattern{
/**
* 整数,不含小数 {@value}
.
*
* 示例:
*
*
*
* 88.6 会被格式化成 89
* -88.6 会被格式化成 -89
*
*
*
*
* @since 1.0.7
*/
public static final String NO_SCALE = "#";
/**
* (2位小数点) {@value}
.
*
* 示例:
*
*
*
* 88.6 会被格式化成 88.60
* -88.067 会被格式化成 -88.07
*
*
*
*
* @since 1.2.2
*/
public static final String TWO_DECIMAL_POINTS = "#0.00";
//---------------------------------------------------------------
/**
* 百分数的表达式(不带小数) {@value}
.
*
* 示例:
*
*
*
* 0 会被格式化成 0%
* 1 会被格式化成 100%
* 100 会被格式化成 10000%
*
*
*
*/
public static final String PERCENT_WITH_NOPOINT = "##%";
/**
* 百分数的表达式(1位小数点) {@value}
.
*
* 示例:
*
*
*
* 0 会被格式化成 0.0%
* 1 会被格式化成 100.0%
* 100 会被格式化成 10000.0%
*
*
*
*
* @since 1.0.7
*/
public static final String PERCENT_WITH_1POINT = "#0.0%";
/**
* 百分数的表达式(2位小数点) {@value}
.
*
* 示例:
*
*
*
* 0 会被格式化成 0.00%
* 1 会被格式化成 100.00%
* 100 会被格式化成 10000.00%
*
*
*
*/
public static final String PERCENT_WITH_2POINT = "#0.00%";
//---------------------------------------------------------------
/** Don't let anyone instantiate this class. */
private NumberPattern(){
//AssertionError不是必须的. 但它可以避免不小心在类的内部调用构造器. 保证该类在任何情况下都不会被实例化.
//see 《Effective Java》 2nd
throw new AssertionError("No " + getClass().getName() + " instances for you!");
}
}