View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Keith Willshaw Keith Willshaw is offline
external usenet poster
 
Posts: 170
Default Can excel calculate?


"Karl Itschen" wrote in message
...
Please note that C++ does it right!

#include <iostream
#include <math.h
using namespace std;
int main()
{
double tempRound;
double tempInt, tempDec;
double number;
number = 64.1;

tempRound =floor(number*10+0.5)/10;
tempInt = (int)(tempRound);
tempDec = 10*(tempRound - tempInt);

cout << "tempRound = " << tempRound << endl;
cout << "tempInt = " << tempInt << endl;
cout << "tempDec = " << tempDec << endl;

system("pause");
return 0;
}

gives the right result:

tempRound = 64.1
tempInt = 64
tempDec = 1


Well of course it does

The default precison used for doubles by cout
is only 6 decimal places

Try

cout.precision(15);

if you want a real comparison.

http://msdn.microsoft.com/library/de...recisio n.asp

Keith