本文介绍了分割值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:
非常简单,但无法在程序中工作,需要帮​​助,我的大脑已经过度使用.
我正在尝试计算值并获取百分比,但最终却得到了0.

整数= 122333; (这里的值可能会扩展到十万)
整数b = 128222;值可以扩展到十万)

int answ = 0;

answ =(a-b);
answ = -5889;
answ =((answ/a)* 100);

answ = 0 =绝对错误
正确的答案应该是:(-4.81)

请增强我的基本代码以获得正确的值,因为我总是得到0

help:-<</xml>

Questions:
Very easy but can''t work in program, need help my brain is over used.
I am trying to calculate the value and get the percentage but I end up getting a 0.

int a = 122333; (value here could expand to hundred thousand)
int b = 128222; value here could expand to hundred thousand)

int answ = 0;

answ = (a - b);
answ = -5889;
answ = ((answ / a) * 100);

answ = 0 = definitely wrong
CORRECT ANSWER SHOULD BE: (-4.81)

Please enhance my basic code to get the right value because I always get 0

help :-<</xml>

推荐答案


answ = ((answ / a) * 100);


整数(-5889/122333) 0 0 * 100 0 ,因此您的程序是正确的.
整数(100 * answ/a)的计算结果为 -588900/122333 ,更接近您的愿望 -4 .

欢呼声,
AR


The integer (-5889 / 122333) is 0, 0 * 100 is 0 so your program is correct.
The integer (100 * answ / a) would evaluate to -588900 / 122333 which is -4 nearer to your wish.

cheers,
AR


int answ = 0;




进入




Into

double answ = 0;



然后



then

answ = ((answ / a) * 100);//= -4,81390957468549


这篇关于分割值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 02:43