How to add numbers to a decimal button My code:
Number = Number * 10 + (integer) [sender tag]; Display2.text = [NSString stringWithFormat: @ "% .10g", number]; And my code for the decimal code.
NSString * currentText = display2.text; If ([current text limit offsetting: @ "" option: nsbuckers search] .length == 0) {display2.text = [display2.text stringbifting string: @ "."]; } How does this work ?! Enter 12 and press Decimal. And press number 3 = 123: (
The reason is that you are getting 123 instead of 12.3 The code for the other button (not the decimal button). However I will go with the limit. Location == To add a border instead of NSNotFound, range.length == 0, this problem is not.
The problem is That you are doing the number * 10 + [sender tag] Now you say that you enter 1, then 2, decimal. "Number" is 12, which is 12. Now, when you multiply it by 10 Add 3, your O 12 * 10 + 3 = 120 + 3 = 123.
The actual number you want to get (12.3) Instead, use it:
Display2.text = [display2.text stringByAppendingFormat: @ "% i", [sender tag]]; At the beginning of this string to get rid of zero, you can do this If: ([display.text isEqualToString: @ "0"]) {display.text = [NSString stringWithFormat: @ "% i", [sender tag]];} and { Display2.text = [displa Y2.text stringByAppendingFormat: @ "% i", [sender tag]]; }
No comments:
Post a Comment