Actionscript 3 Flex中奇怪的数字格式行为,AS3

Actionscript 3 Flex中奇怪的数字格式行为,AS3,actionscript-3,apache-flex,numberformatter,Actionscript 3,Apache Flex,Numberformatter,我在AS3中使用NumberFormatter时遇到了这种奇怪的行为 了解我需要使用NumberBaseRoundType.UP是很重要的,因为我在申请信用证时需要使用NumberBaseRoundType.DOWN 考虑到值为2的舍入精度,我想NumberFormatter不应该更改我的数字。在下面的示例中,2.43一旦格式化,将变为2.44 因此,Math.pow(…)不是我正在寻找的解决方案,另外,我非常有兴趣了解发生了什么以及为什么会发生这种情况。谢谢 var roundUp:Numbe

我在AS3中使用NumberFormatter时遇到了这种奇怪的行为

了解我需要使用
NumberBaseRoundType.UP
是很重要的,因为我在申请信用证时需要使用
NumberBaseRoundType.DOWN

考虑到值为2的舍入精度,我想NumberFormatter不应该更改我的数字。在下面的示例中,2.43一旦格式化,将变为2.44

因此,
Math.pow(…)
不是我正在寻找的解决方案,另外,我非常有兴趣了解发生了什么以及为什么会发生这种情况。谢谢

var roundUp:NumberFormatter = new NumberFormatter();
roundUp.rounding = NumberBaseRoundType.UP;
roundUp.precision = 2;

trace(roundUp.format(2.41)); // Output : 2.41
trace(roundUp.format(2.42)); // Output : 2.42
trace(roundUp.format(2.43)); // Output : 2.44 <-- ???
trace(roundUp.format(2.44)); // Output : 2.44
trace(roundUp.format(2.45)); // Output : 2.46 <-- ???
trace(roundUp.format(2.46)); // Output : 2.46
var-roundUp:NumberFormatter=newnumberformatter();
roundUp.rounding=NumberBaseRoundType.UP;
roundUp.precision=2;
跟踪(roundUp.format(2.41));//产出:2.41
跟踪(roundUp.format(2.42));//产出:2.42

跟踪(roundUp.format(2.43));//输出:2.44这不是一个完整的答案。但首先,您使用的是哪个NumberFormatter类(它来自于什么包)。有些源代码是可用的,有些源代码包含在播放器本身中,无法访问,但在查看4.6框架中Spark中包含的on时,它包含了这个类级别的注释,提供了一些见解:

/**
 *  The NumberFormatter class provides locale-sensitive formatting
 *  and parsing of numeric values. It can format <code>int</code>,
 *  <code>uint</code>, and <code>Number</code> objects.
 *
 *  <p>This class is a wrapper class around the 
 *  flash.globalization.NumberFormatter class. 
 *  Therefore, the locale-specific formatting
 *  is provided by the flash.globalization.NumberFormatter.
 *  However, this NumberFormatter class can be used in MXML declarations,
 *  uses the locale style for the requested Locale ID name, and has
 *  methods and properties that are bindable.  
 *  </p>
 *
 *  <p>The flash.globalization.NumberFormatter class use the
 *  underlying operating system for the formatting functionality and
 *  to supply the locale-specific data. On some operating systems, the
 *  flash.globalization classes are unsupported, on these systems this wrapper
 *  class provides fallback functionality.</p>
 *
 *  @mxml <p>The <code>&lt;s:NumberFormatter&gt;</code> tag inherits all of the tag 
 *  attributes of its superclass and adds the following tag attributes:</p>
 *
 *  <pre>
 *  &lt;s:NumberFormatter 
 *    <strong>Properties</strong>
 *    negativeNumberFormat="<i>locale and OS dependent</i>"
 *  /&gt;
 *  </pre>
 *
 *  @includeExample examples/NumberFormatterExample1.mxml
 *  @includeExample examples/NumberFormatterExample2.mxml
 *
 *  @see flash.globalization.NumberFormatter
 * 
 *  @langversion 3.0
 *  @playerversion Flash 10.1
 *  @playerversion AIR 2.5
 *  @productversion Flex 4.5
 */
* *@includeExample示例/NumberFormatterExample1.mxml *@includeExample示例/NumberFormatterExample2.mxml * *@see flash.globalization.NumberFormatter * *@langversion 3.0 *@playervision Flash 10.1 *@playervision-AIR 2.5 *@productversion Flex 4.5 */
最终,尽管它声明播放器以某种方式使用底层操作系统来实现格式化。这当然是一个奇怪的问题,但如果这之前从未被发现,并且没有发布解释,或者至少没有错误报告(如果它实际上是flash player中的一个问题),我会感到惊讶。关于你的SDK版本和播放器版本的更多细节可能会有所帮助,你也尝试过摆弄这两个版本中的任何一个吗?结果有什么变化吗


另外,根据您试图实现的目标,如果您需要处理的只是一次性场景,那么您可以通过编写自己的类来处理这种情况下的格式设置,从而绕过这个问题,如果它更像是一个系统范围内使用的东西,需要更多NumberFormatter类的功能,我可以理解想要解决根本问题。

这不是一个完整的答案。但首先,您使用的是哪个NumberFormatter类(它来自于什么包)。有些源代码是可用的,有些源代码包含在播放器本身中,无法访问,但在查看4.6框架中Spark中包含的on时,它包含了这个类级别的注释,提供了一些见解:

/**
 *  The NumberFormatter class provides locale-sensitive formatting
 *  and parsing of numeric values. It can format <code>int</code>,
 *  <code>uint</code>, and <code>Number</code> objects.
 *
 *  <p>This class is a wrapper class around the 
 *  flash.globalization.NumberFormatter class. 
 *  Therefore, the locale-specific formatting
 *  is provided by the flash.globalization.NumberFormatter.
 *  However, this NumberFormatter class can be used in MXML declarations,
 *  uses the locale style for the requested Locale ID name, and has
 *  methods and properties that are bindable.  
 *  </p>
 *
 *  <p>The flash.globalization.NumberFormatter class use the
 *  underlying operating system for the formatting functionality and
 *  to supply the locale-specific data. On some operating systems, the
 *  flash.globalization classes are unsupported, on these systems this wrapper
 *  class provides fallback functionality.</p>
 *
 *  @mxml <p>The <code>&lt;s:NumberFormatter&gt;</code> tag inherits all of the tag 
 *  attributes of its superclass and adds the following tag attributes:</p>
 *
 *  <pre>
 *  &lt;s:NumberFormatter 
 *    <strong>Properties</strong>
 *    negativeNumberFormat="<i>locale and OS dependent</i>"
 *  /&gt;
 *  </pre>
 *
 *  @includeExample examples/NumberFormatterExample1.mxml
 *  @includeExample examples/NumberFormatterExample2.mxml
 *
 *  @see flash.globalization.NumberFormatter
 * 
 *  @langversion 3.0
 *  @playerversion Flash 10.1
 *  @playerversion AIR 2.5
 *  @productversion Flex 4.5
 */
* *@includeExample示例/NumberFormatterExample1.mxml *@includeExample示例/NumberFormatterExample2.mxml * *@see flash.globalization.NumberFormatter * *@langversion 3.0 *@playervision Flash 10.1 *@playervision-AIR 2.5 *@productversion Flex 4.5 */ 最终,尽管它声明播放器以某种方式使用底层操作系统来实现格式化。这当然是一个奇怪的问题,但如果这之前从未被发现,并且没有发布解释,或者至少没有错误报告(如果它实际上是flash player中的一个问题),我会感到惊讶。关于你的SDK版本和播放器版本的更多细节可能会有所帮助,你也尝试过摆弄这两个版本中的任何一个吗?结果有什么变化吗


另外,根据您试图实现的目标,如果您需要处理的只是一次性场景,那么您可以通过编写自己的类来处理这种情况下的格式设置,从而绕过这个问题,如果它更像是一个系统范围内使用的东西,需要更多NumberFormatter类的功能,我可以理解,想要解决根本问题。

我相信他使用的是MX NumberFormatter,因为Spark one没有定义
舍入
精度
属性。您好,我正在使用FB 4.0.1中SDK 4.1.0中包含的mx.formatters.NumberFormatter类。当然,我将不得不写我自己的课程,因为会计系统肯定不能依赖于计算机语言环境。。我在加拿大,但我总是使用美国设置来避免任何问题。。现在,我不知道。。但我会试着做一些测试,然后回复你们。谢谢我相信他使用的是MX NumberFormatter,因为Spark one没有定义
舍入
精度
属性。您好,我使用的是FB 4.0.1中SDK 4.1.0中包含的MX.formatters.NumberFormatter类。当然,我将不得不写我自己的课程,因为会计系统肯定不能依赖于计算机语言环境。。我在加拿大,但我总是使用美国设置来避免任何问题。。现在,我不知道。。但我会试着做一些测试,然后回复你们。谢谢