我知道double/float的问题,建议使用BigDecimal而不是double/float来表示货币字段.但是双/浮动更有效且节省空间.然后我的问题是:使用double/float来表示Java类中的货币字段是可以接受的,但是使用BigDecimal来处理算术(即在任何算术之前将double/float转换为BigDecimal)和等同检查?
原因是节省了一些空间.我真的看到很多项目正在使用double/float来代表货币领域.
这有什么陷阱吗?提前致谢.
当我在Python中学习"命名和绑定"时,我看到了以下示例:
>>> def testClosure(maxIndex):
def closureTest(maxIndex=maxIndex):
return maxIndex
maxIndex += 5
return closureTest()
>>> print(testClosure(10))
10
>>> def testClosure(maxIndex):
def closureTest():
return maxIndex
maxIndex += 5
return closureTest()
>>> print(testClosure(10))
15
Run Code Online (Sandbox Code Playgroud)
作者将其解释为:在后一个函数中,内部作用域中的自由变量绑定到外部作用域中的变量,而不是对象.
然后我的问题是:Python中"绑定到变量"和"绑定到对象"之间的区别是什么?
此外,它非常棘手:如果我重新安排代码,结果会有所不同.
>>> def testClosure(maxIndex):
maxIndex += 5
def closureTest(maxIndex=maxIndex):
return maxIndex
return closureTest()
>>> print(testClosure(10))
15
Run Code Online (Sandbox Code Playgroud)
提前致谢.