本文介绍了如何让一个整数作为结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了针对Android这需要三个输入,使计算应用程序

 其他{
    浮RESULT1 =(((新的浮动(input11.getText()。的toString())
                     +新浮动(input21.getText()的toString()))/ 2));
    浮结果2 =(新的浮动(input31.getText()的toString());
    如果(RESULT1≤(结果2 - 2)){
       RESULT1 = result2-2;
       float结果=(浮点)((新的浮动(RESULT1)* 0.3)+(新的浮动(RESULT2)* 0.7));
       vprosvasis.setText(Float.toString(结果));
    }
    否则,如果(RESULT1>(RESULT2 + 2)){
       RESULT1 =结果2 + 2;
       float结果=(浮点)((新的浮动(RESULT1)* 0.3)+(新的浮动(RESULT2)* 0.7));
       vprosvasis.setText(Float.toString(结果));
    }
    其他{
       float结果=(浮点)((((新的浮动(input11.getText()。的toString())
                                +新浮动(input21.getText()。的toString()))/ 2)* 0.3)
                                (。新的浮动(input31.getText()的toString())* 0.7)+);
       vprosvasis.setText(Float.toString(结果));
    }
}

首先,我想结果在每一个语句是e.x. 12.35,不12,342323 ...
其次,我得到相同的方式vprosvasis2-vprosvasis7.i想最后的结果,我打印是一个整数,而不是浮动。

 浮动vprosvasisFloat = Float.parseFloat(vprosvasis.getText()的toString());
浮vprosvasisFloat2 = Float.parseFloat(vprosvasis2.getText()的toString());
浮vprosvasisFloat7 = Float.parseFloat(vprosvasis7.getText()的toString());
浮vprosvasisFloat5 = Float.parseFloat(vprosvasis6.getText()的toString());
浮vprosvasisFloat4 = Float.parseFloat(vprosvasis7.getText()的toString());
浮vprosvasisFloat3 = Float.parseFloat(vprosvasis6.getText()的toString());
浮vprosvasisFloat6 = Float.parseFloat(vprosvasis5.getText()的toString());
浮动genikosvathmosoik =((新的浮动(vprosvasis.getText()。的toString())
               +新浮动(vprosvasis2.getText()。的toString())
               +新浮动(vprosvasis3.getText()。的toString())
               +新浮动(vprosvasis4.getText()。的toString())
               +新浮动(vprosvasis5.getText()。的toString())
               +新浮动(vprosvasis6.getText()。的toString())
                           +新浮动(vprosvasis7.getText()的toString()))/ 7);moria2oik =(((新浮动((genikosvathmosoik * 8)+(vprosvasisFloat * 1.3)+(vprosvasisFloat2 * 0.7))* 100)));
moria3oik =(((新浮动((genikosvathmosoik * 8)+(vprosvasisFloat4 * 1.3)+(vprosvasisFloat3 * 0.7))* 100)));
moria5oik =(((新浮动((genikosvathmosoik * 8)+(vprosvasisFloat7 * 1.3)+(vprosvasisFloat6 * 0.7))* 100)));
开关(spinner.getSelectedItemPosition()){
    情况下0:
        秀=新AlertDialog.Builder(mContext).setTitle(R.string.app_name)
                              .setMessage(1O: - \\ N2O
                                         + moria2oik +\\ n3o:
                                         + moria3oik +\\ n4o:
                                         + moria2oik +\\ n5o:
                                         + moria5oik)
                              .setPositiveButton(OK,空).show();
    打破;


解决方案

如果我理解正确的问题,你应该看看数学类的Java。 是开发者文档。

当涉及到操纵浮动或数学类可以做几乎所有的两倍。

您可能想看看其他类是 DecimalFormat的可以做什么是说,格式小数。 :)可用 rel=\"nofollow\">。

I have created an application for android that takes three inputs and makes a calculation

else {
    float result1 = (((new Float(input11.getText().toString())
                     + new Float(input21.getText().toString()))/2));
    float result2 = (new Float(input31.getText().toString());
    if(result1<(result2 - 2)) {
       result1 = result2-2;
       float result=(float) ( (new Float(result1)*0.3)+(new Float(result2)*0.7));
       vprosvasis.setText(Float.toString(result));
    }
    else if(result1>(result2 + 2)) {
       result1=result2+2;
       float result=(float) ( (new Float(result1)*0.3)+(new Float(result2)*0.7));
       vprosvasis.setText(Float.toString(result));
    }
    else {
       float result = (float) ((((new Float(input11.getText().toString())
                                + new Float(input21.getText().toString()))/2)*0.3)
                                + (new Float(input31.getText().toString())*0.7));
       vprosvasis.setText(Float.toString(result));
    }
}

Firstly,i would like the result in every statement to be e.x. 12.35 ,not 12,342323...Secondly,i get in the same way vprosvasis2-vprosvasis7.i would like the final result that i print to be an integer and not a float..

float vprosvasisFloat = Float.parseFloat(vprosvasis.getText().toString());
float vprosvasisFloat2 = Float.parseFloat(vprosvasis2.getText().toString());
float vprosvasisFloat7 = Float.parseFloat(vprosvasis7.getText().toString());
float vprosvasisFloat5 = Float.parseFloat(vprosvasis6.getText().toString());
float vprosvasisFloat4 = Float.parseFloat(vprosvasis7.getText().toString());
float vprosvasisFloat3 = Float.parseFloat(vprosvasis6.getText().toString());
float vprosvasisFloat6 = Float.parseFloat(vprosvasis5.getText().toString());
float genikosvathmosoik = (( new Float(vprosvasis.getText().toString())
               + new Float(vprosvasis2.getText().toString())
               + new Float(vprosvasis3.getText().toString())
               + new Float(vprosvasis4.getText().toString())
               + new Float(vprosvasis5.getText().toString())
               + new Float(vprosvasis6.getText().toString())
                           + new Float(vprosvasis7.getText().toString())) / 7);

moria2oik = (((new Float ((genikosvathmosoik*8)+(vprosvasisFloat * 1.3)+(vprosvasisFloat2 * 0.7))*100)));
moria3oik=(((new Float ((genikosvathmosoik*8)+(vprosvasisFloat4 * 1.3)+(vprosvasisFloat3 * 0.7))*100)));
moria5oik=(((new Float ((genikosvathmosoik*8)+(vprosvasisFloat7 *1.3)+(vprosvasisFloat6 * 0.7))*100)));
switch(spinner.getSelectedItemPosition()){
    case 0:
        show = new AlertDialog.Builder(mContext).setTitle(R.string.app_name)
                              .setMessage("1o :  -\n2o :  "
                                         + moria2oik + "\n3o :  "
                                         + moria3oik + "\n4o :  "
                                         + moria2oik + "\n5o :  "
                                         + moria5oik)
                              .setPositiveButton("OK", null).show();
    break;

If I understand the question correctly, you should look into the Math class of Java. Here is the developer doc.

The math class can do almost everything when it comes to manipulating a float or double.

The other class you might want to look at is DecimalFormat which can do exactly what is says, format decimals. :) That is available here.

这篇关于如何让一个整数作为结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 16:50