gpt4 book ai didi

java - 使用 NumberFormat 格式化数字的 FieldPosition

转载 作者:行者123 更新时间:2023-11-29 05:38:54 25 4
gpt4 key购买 nike

任何人都可以解释以下摘自 API 的内容用简单的英语?

You can also use forms of the parse and format methods with ParsePosition and FieldPosition to allow you to:

progressively parse through pieces of a string

align the decimal point and other areas

For example, you can align numbers in two ways: If you are using a monospaced font with spacing for alignment, you can pass the FieldPosition in your format call, with field = INTEGER_FIELD. On output, getEndIndex will be set to the offset between the last character of the integer and the decimal. Add (desiredSpaceCount - getEndIndex) spaces at the front of the string.

我不知道 FieldPosition 的用途是什么,上面发布的 API 没有帮助(至少对我而言)。显示输出的一个简单示例将是 super 的!提前致谢!

最佳答案

FieldPosition 的 java 文档和 ParsePosition类(class)提供更多提示。

基本上,如果您不想格式化整个日期或数字,而只想格式化其中的一部分(例如,如果您的 UI 将金额分成几个部分(例如在两个输出字段中给出美元和美分),则可以使用 FieldPosition。如果您需要类似的东西,您可以使用 FieldPosition 来检索您感兴趣的部分。对于 ParsePosition,我现在没有一个好的用例,也许其他人可以在这里提供帮助。

关于java - 使用 NumberFormat 格式化数字的 FieldPosition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18432866/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com