|
From: duraisridhar on 24 Jun 2008 12:56 Hi All, My coding have following stmt in which I divide large number say X by number y which is sligthly greater then X. Say Y = X + 1 double successRate = 0; double passedCandidates = 10000000 ; double failedCandidates = 1; sucessRate = (passedCandidates * 100) / ( passedCandidates + failedCandidates ); In the above stmt , I always get 100 % while I except 99.9999. . I tried type casting sucessRate to float , but still i get 100 %. When the failedCandiates value is 20, I get success rate as 99.99. Is thier any way (using floor ) i can success rate less then 100 when Y is greater then X. Thanks in advance, Regards, Sri --
From: Salt_Peter on 24 Jun 2008 13:27 On Jun 24, 12:56 pm, duraisrid...(a)gmail.com wrote: > Hi All, > > My coding have following stmt in which I divide large number say X by > number y which is sligthly greater then X. Say Y = X + 1 > > double successRate = 0; > double passedCandidates = 10000000 ; > double failedCandidates = 1; > > sucessRate = (passedCandidates * 100) / ( passedCandidates + > failedCandidates ); > > In the above stmt , I always get 100 % while I except 99.9999. . I > tried type casting sucessRate to float , but still i get 100 %. When > the failedCandiates value is 20, I get success rate as 99.99. > > Is thier any way (using floor ) i can success rate less then 100 when > Y is greater then X. > > Thanks in advance, > > Regards, > Sri > > -- Include <iomanip> and use setprecision(#) to manipulate your output's displayed precision. Something as follows: std::cout << setflags(ios::fixed) << setprecision(10) << sucessRate << std::endl; In other words, 100 is a perfectly legal representation of 99.9999 depending on the precision requested.
From: R. Scott Mellow on 24 Jun 2008 13:34 duraisridhar(a)gmail.com wrote: > Hi All, > > My coding have following stmt in which I divide large number say X by > number y which is sligthly greater then X. Say Y = X + 1 > > double successRate = 0; > double passedCandidates = 10000000 ; > double failedCandidates = 1; > > sucessRate = (passedCandidates * 100) / ( passedCandidates + > failedCandidates ); > > In the above stmt , I always get 100 % while I except 99.9999. . I > tried type casting sucessRate to float , but still i get 100 %. When > the failedCandiates value is 20, I get success rate as 99.99. How are you looking at the value? Without seeing the actual code it would be guesswork to suggest the problem or its solution. How is your code different from this small, compilable example: #include <iostream> int main() { double passed = 10000000.0; double failed = 1.0; double rate = (passed * 100) / (passed + failed); std::cout << rate << '\n'; return 0; } -- Randy
From: duraisridhar on 25 Jun 2008 09:57 Hi, Yes, my coding will be similar to your example. In the your above example, I tried changing the data type of both variables 'passed' and 'failed'. The output was expected result less then 100. Regards, Sri On Jun 24, 10:34 pm, "R. Scott Mellow" <fil...(a)rsmellow.com> wrote: > duraisrid...(a)gmail.com wrote: > > Hi All, > > > My coding have following stmt in which I divide large number say X by > > number y which is sligthly greater then X. Say Y = X + 1 > > > double successRate = 0; > > double passedCandidates = 10000000 ; > > double failedCandidates = 1; > > > sucessRate = (passedCandidates * 100) / ( passedCandidates + > > failedCandidates ); > > > In the above stmt , I always get 100 % while I except 99.9999. . I > > tried type casting sucessRate to float , but still i get 100 %. When > > the failedCandiates value is 20, I get success rate as 99.99. > > How are you looking at the value? Without seeing the actual code it would be > guesswork to suggest the problem or its solution. How is your code different > from this small, compilable example: > > #include <iostream> > > int main() > { > double passed = 10000000.0; > double failed = 1.0; > double rate = (passed * 100) / (passed + failed); > > std::cout << rate << '\n'; > > return 0; > > } > > -- > Randy
|
Pages: 1 Prev: computer Next: cheap discount prada chanel coach puma versace wallet sneakers |