public class FractionFormat
extends java.text.Format
Format class that handles Excel style fractions, such as "# #/#" and "#/###"
As of this writing, this is still not 100% accurate, but it does a reasonable job of trying to mimic Excel's fraction calculations. It does not currently maintain Excel's spacing.
This class relies on a method lifted nearly verbatim from org.apache.math.fraction. If further uses for Commons Math are found, we will consider adding it as a dependency. For now, we have in-lined the one method to keep things simple.
(处理 Excel 样式分数的格式类,例如“##/#”和“#/###” 在撰写本文时,这仍然不是 100% 准确,但它在尝试模仿 Excel 的分数计算方面做得很合理.它目前不保持 Excel 的间距。此类依赖于从 org.apache.math.fraction 中几乎逐字逐句提升的方法。如果发现 Commons Math 的进一步用途,我们将考虑将其添加为依赖项。目前,我们已经内联了一种使事情变得简单的方法。)Constructor and Description |
---|
FractionFormat(java.lang.String wholePartFormatString, java.lang.String denomFormatString)
Single parameter ctor
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
format(java.lang.Number num) |
java.lang.StringBuffer |
format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos) |
java.lang.Object |
parseObject(java.lang.String source, java.text.ParsePosition pos) |
public FractionFormat(java.lang.String wholePartFormatString, java.lang.String denomFormatString)
denomFormatString
- The format string for the denominator
(denomFormatString - 分母的格式字符串)
public java.lang.String format(java.lang.Number num)
public java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
format
in class
java.text.Format
(类 java.text.Format 中的格式)
public java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)
parseObject
in class
java.text.Format
(类 java.text.Format 中的 parseObject)
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.