gpt4 book ai didi

java - 我如何进行像 5' 3"1/2 这样的测量,然后将其乘以 1.414 并在 android java 上以相同的格式显示答案

转载 作者:行者123 更新时间:2023-12-01 15:19:01 25 4
gpt4 key购买 nike

我正在做的是这样的,我保留 5',然后除以 12,将 3"转换为英尺的小数,然后将分子除以分母,然后将其全部相加并乘以 1.414它有效,但我不知道如何显示英尺英寸和英寸的分数

    c2c_fdecimal = f_num / f_den;
c2c_fdeci_fft = c2c_fdecimal / 12.0;
deci_of_foot = inchs / 12.0;
total_travel= feet + c2c_fdeci_fft + deci_of_foot;

toff_ftodeci = tkoff_numa / tkoff_dena;
tkoff_inch = tkoff_inch / 12.0;
sub_toff = toff_ftodeci / 12.0 + tkoff_inch;
ans = (total_travel * ffformula) - sub_toff;
//print out measurement format
ansint = (int)ans;
strip_inches = (int) ((ans - ansint) * 12.0);
//print answer
editText2.setText(ansint + " ft" + strip_inches + " in");

最佳答案

以下是在 Java 中计算英尺和英寸的方法:

double resultInInches; // you start with inches...
int feet = (int)(resultInInches / 12);
double rest = (resultInInches / 12) - feet;
int wholeInches = (int)rest;
rest = rest-wholeInches; // rest now holds the fraction of the inch, eg 0.4141

现在剩下要做的就是将 rest 显示为分数。我不熟悉 Android SDK 中允许或不允许的内容,并且有很多方法可以做到这一点(请参阅 this answer )。

关于java - 我如何进行像 5' 3"1/2 这样的测量,然后将其乘以 1.414 并在 android java 上以相同的格式显示答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11237152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com