简体   繁体   English

Java Android Studio新手,需要一些指导

[英]New to Java Android Studio, need some guidance

i'm new here and to Java Android Studio. 我是新来的和Java Android Studio。

Currently i creating an App which functions as below : 目前我正在创建一个App,其功能如下:

  1. User key-in a digit for example 1131 用户键入一个数字,例如1131
  2. The App will take 1131 / 80 = 14.1375 该应用程序将采取1131/80 = 14.1375
  3. And the calculation will remove all the front digit which is the 14 并且计算将删除所有前面的数字,即14
  4. Use 0.1375 and Times 80 使用0.1375和时间80
  5. Results = 11 结果= 11
  6. Then the App will display a certain message for the number 11 然后,应用程序将显示数字11的特定消息

So far i'm stuck at the calculation which is For Example : 到目前为止,我仍然坚持计算,例如:

int x = 1131;
double x1 = x / 80.0;              //Gets 14.1375
double x2 = Math.floor(x1);        //Gets 14.0
double x3 = x1 - x2;               //14.1375 - 14.0 = 0.1374999999999993 ???

something weird shows up during the Math.floor, it suppose to take 14 and execute x1 - x2 ( 14.1375 - 14.0 = 0.1375 ) 在Math.floor中出现一些奇怪的东西,它假设需要14并执行x1 - x2(14.1375 - 14.0 = 0.1375)

But instead it shows 0.1374999999999993 但相反它显示0.1374999999999993

Thank you !! 谢谢 !!

This is because numbers in computer languages are represented by binary. 这是因为计算机语言中的数字由二进制表示。 See the answer posted here 看到这里发布的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM