开发者

How to handle when the backspace button is pressed and the input panel has digit grouped numbers. E.g. 434,343,334.232

I am making a calculator in c# for the windows phone and I'm struggling right now.

Say the user wrote the digits 123,456. What I want to happen is when the user hits the backspace key, the comma stays in place and when the number 3 is deleted, so is the comma. Right now when the user hits the backspace key, the comma is deleted as the digits are being deleted. So when you erase the 6 and 5, 123,4 is left.

Any h开发者_C百科elp is highly appreciated. Thank you.


You could use String.Format("{0:n}", value) for displaying the numbers with commas. If the user enters commas, strip them when storing them in your program.

Basically, you can store the number internally in the program as a numeric type (such as Decimal). When the user hits the backspace key (or otherwise enters text), parse the numeric value out of the string and then update the display with the String.Format operation using the numeric value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜