文本框将输入转换为货币值 [英] Textbox converts input into currency value

查看:98
本文介绍了文本框将输入转换为货币值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在寻找以下问题的提示或提示.

我有一个文本框.用户只能插入数字,我想将输入转换为货币值

例如:

用户插入564
然后tb将其转换为某种形式:€5,64

或:
用户插入65
-> tb转换为:€0,65


输入:456125
->转换:€4.561,25

我的问题是写方向:我希望用户从右到左写,所以您首先写"4",光标跳到行的右端,而不是写5,依此类推.

我已经尝试过很多带有mask的maskedTextBox之类的东西:
$#,###,###.#0

$ ###.##
等等

我也尝试过
string.format("{0:c}");
但是在这里,当我插入例如15354时,结果如下:15.354,00€
我想要,"后的最后2位数字,


我希望你了解我的问题在哪里.我还没有完成代码,只是一个提示之类的东西.

Hi,

I''m looking for a tip or hint for the following problem.

I have a Textbox. The user can only insert digits and i want to transform the input to a currency value

e.g.:

The user inserts 564
and the tb converts it into some kind of: € 5,64

or:
the users inserts 65
-> tb converts it into: € 0,65

or
input: 456125
-> convert: € 4.561,25

my problem is the write direction: i want the user to write right to left, so you first write the "4", the cursor jumps to the right end of line, than you write the 5 and so on

I''ve tried many thing like maskedTextBox with mask:
$ #,###,###.#0
or
$ ###.##
and so on

i''ve also tried
string.format("{0:c}");
But here i get, when i insert for example 15354 this result : 15.354,00 €
i want the last 2 digits behind the ","


i hope you understood where''s my problem. I don''t a finished code, just a hint or something..
Thanks in advance!

推荐答案

#,###,###.#0

#,###,###.#0
or


###.##
等等

我也尝试过
string.format("{0:c}");
但是在这里,当我插入例如15354时,结果如下:15.354,00€
我想要,"后的最后2位数字,


我希望你了解我的问题在哪里.我还没有完成代码,只是一个提示之类的东西.
预先感谢!
###.##
and so on

i''ve also tried
string.format("{0:c}");
But here i get, when i insert for example 15354 this result : 15.354,00 €
i want the last 2 digits behind the ","


i hope you understood where''s my problem. I don''t a finished code, just a hint or something..
Thanks in advance!


如果要将字符串转换为例如double,为什么不简单地将其除以100并将其用于输出. (可选)您可以先检查是否存在小数点分隔符,如果不存在,则不要使用除法.

我猜最棘手的部分是格式.为此,您可以将击键存储在一个单独的,不断增长的字符串中,该字符串将在文本框中正确设置格式.因此,文本框实际上只会显示您的字符串变量的内容.
If you''re converting the string to for example double, why not simply divide it by 100 and use that for your output. Optionally you can first check if decimal separator is present and if it is, then don''t use division.

I''d guess the tricky part would be the formatting. For this you could store the keystrokes in a separate, constantly growing string which the would be properly formatted in your textbox. So the text box would actually just show the contents of your string variable.


这篇关于文本框将输入转换为货币值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆