问题描述
我正在编写一个简单计算器,只是为了开始使用iPhone开发人员.问题是我有一个(-)按钮,该按钮应该通过执行简单的*-1
来抵消已经放置在屏幕上的任何内容.除非上一个输入是0
,否则它工作正常.
I'm coding a simple calculator just to get started with iPhone dev. The thing is I have a (-) button thats supposed to negate whatever is put to the screen already by doing a simple *-1
. It works fine except when the previous input is 0
.
场景:在屏幕为空或0
的情况下,我点击(-)取反.然后,当我点击例如9
时,我希望它读取(或者更确切地说是 be )-9
.现在不是9
.仅供参考,我在世界各地的atm都使用原始整数,但是我准备中止它.
Scenario: With empty screen or 0
, I tap (-) to negate. Then when I tap for example 9
I want it to read (or rather be) -9
. Not 9
as it is now. FYI I'm atm working with primitive ints everywhere but I'm prepared to abort that.
问题:如何表示负数0?我可以使用支持它的数据类型吗? NSInteger?
Questions: How to represent negative 0? Is there a data type I can use that supports it? NSInteger?
或者是使用状态boolean和stringWithFormat等进行某些变通方法的唯一方法吗?
Or is the only way to do some hacky workaround with state boolean and stringWithFormat etc?
感谢帮助. /O
推荐答案
float
和double
支持-0
(如果提供内存,则与0
不同).有关更多信息,请参见此处,尽管我不相信使用-0对用户特别有用.您是否有一个需要它的引人注目的用例?
float
and double
support -0
(which is different than 0
if memory serves). See here for more information, though I'm not convinced using -0
in your application will be particularly helpful for users. Do you have a compelling use case that requires it?
这篇关于有负零吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!