Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是android的初学者。我正在开发一个与销售相关的应用程序,我需要在其中进行大量计算。 我很困惑使用哪些变量来处理价格、折扣等。
目前我将价格存储为整数。例如180 Rs ---> 18000 Paise & while Showing 我简单地将它除以 100。
但我想显示价格/折扣至小数点后 2 位,如 150.50 Rs 或 20.50Rs。 我应该使用什么?浮点数或双精度数或其他任何东西? 请帮帮我...谢谢...
在计算价格时使用整数:您将避免四舍五入的问题。当您想转换为实际价格时,只需除以 100。并在java.text.NumberFormat每次要显示价格时使用 a:您将控制它将打印的确切小数位数。
java.text.NumberFormat