F
ferran
Hi, does anybody know how to convert in C++ from base 10 to any other
base without loosing the decimal part of the actual value?
I came up with this algorithm to convert from decimal to any base but
I'm not sure what to do to include the decimal part.
//-----------------------------------------------------------
const char ccBaseChars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char sResult [80] = {0};
int iBase;
int iRemainder;
long double dValue = 14.3;
while (dValue > 0)
{
iRemainder = std::floorl(std::fmodl(dValue , iBase), 0);
Value = std::floorl(dValue / iBase);
if (iRemainder == iBase)
sResult = sResult + ccBaseChars [0];
else
sResult = sResult + ccBaseChars [iRemainder];
}
//-----------------------------------------------------------
<>Thanks for any help
base without loosing the decimal part of the actual value?
I came up with this algorithm to convert from decimal to any base but
I'm not sure what to do to include the decimal part.
//-----------------------------------------------------------
const char ccBaseChars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char sResult [80] = {0};
int iBase;
int iRemainder;
long double dValue = 14.3;
while (dValue > 0)
{
iRemainder = std::floorl(std::fmodl(dValue , iBase), 0);
Value = std::floorl(dValue / iBase);
if (iRemainder == iBase)
sResult = sResult + ccBaseChars [0];
else
sResult = sResult + ccBaseChars [iRemainder];
}
//-----------------------------------------------------------
<>Thanks for any help