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.
精彩评论