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

﹥>﹥吖頭↗ 提交于 2020-02-16 08:40:09

问题


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 help is highly appreciated. Thank you.


回答1:


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.



来源:https://stackoverflow.com/questions/5307129/how-to-handle-when-the-backspace-button-is-pressed-and-the-input-panel-has-digit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!