View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Karl Itschen Karl Itschen is offline
external usenet poster
 
Posts: 3
Default Can excel calculate?

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

Hmmm. Can one trust VBA or not?
Karl
-----Original Message-----
What, exactly, is the problem? Computer floating point
arithmetic is not exact. 0.999999999999943 is very close
to 1 (5.7E-12% deviation is negligible for most
applications).
.