使用 flex 将数字转换为单词

发布于 2024-08-31 09:19:43 字数 182 浏览 2 评论 0原文

我正在尝试使用 Flex 中的数字步进器将条目转换为单词以在文本区域中显示。

即,用户使用步进器输入“89”作为值,并且在文本区域中显示单词“89”。

经过多次搜索,我没有找到任何有帮助的东西 - 一些 javascript 函数,但仅此而已。

任何帮助示例代码将不胜感激。

提前致谢。

I am trying to convert an entry using a numeric stepper in flex into words to display in a textarea.

i.e a user uses the stepper to enter "89" as a value and in the text area the words "Eighty nine" are displayed.

After much searching i haven't found anything that helps - a few javascript functions but that is all.

any help sample code would be much appreciated.

thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余厌 2024-09-07 09:19:43

我建议您制作一个哈希表,其中数字“0”到“99”作为索引(用引号引起来),值是这些数字的单词名称。这将使本地化成为可能,而无需使用大量复杂的代码来确定,例如,日语中“eleven”和“juu ichi”(ten one)之间的区别,或者“ninety-nine”和“ninety-nine”之间的区别。法语中的“quatre vingt dix neuf”(八十九),德语中的“二十二”和“zwei und zwanzig”(二和二十)等等。

让我们将该哈希表命名为 myNumberWords。然后,您只需按如下方式转换数字:

function getWordsFromNumber(num:Number) : String {
  return myNumberWords[num.toString()]; 
}

如果您想要高于 99,请为单词 百万 添加哈希值>、十亿等,然后将整个数字分成一个数组,并在每第三个数字后面放置适当的单位,从堆栈顶部开始计数。您还必须将零值和双零值计为空字符串 (""),除非只有一位数字且为零,等等。

I would suggest you make a hash table with the numbers "0" to "99" as indices (enclosed in quotes) and the values being the word names for those numbers. That will make localization possible without out a lot of complicated code to determine, for example, the difference between "eleven" and "juu ichi" (ten one) in Japanese or between "ninety-nine" and "quatre vingt dix neuf" (eighty-nineteen) in French, "twenty-two" and "zwei und zwanzig" (two and twenty) in German, etc.

Let's name that hash table myNumberWords. Then you would simply convert your digits as follows:

function getWordsFromNumber(num:Number) : String {
  return myNumberWords[num.toString()]; 
}

If you want to go higher than 99, add a hash for the words hundred, thousand, million, billion, etc., then split your whole number into an array and place the appropriate units after every 3rd number, counting from the top of the stack. You'll also have to have zero values and double-zero values counted as empty strings ("") except when there is only one digit and it is a zero, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文