ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Общий форум

a strange float point error
Послано tjq(killer of zju) 21 фев 2001 13:00
in the 1070 local time, I find some error when converting
double to int,

int main()
{
double f=0.12;
int t;
t=int(f)*60+(f-int(f))*100;
cout<<t<<endl;
return 0;
}

I expect to get 12, but the result is 11, many compilers
were tested, can anyone tell me how to avoid this?
Re: a strange float point error
Послано Marat Bakirov 21 фев 2001 14:13
I am afraid you van do nothing except smth like round
(0.12*100)

You see, because double values are really stored in binary
format, numbers that can't be presented with  a degree  2
denominator (2,8,128,etc) are presented by approximation.
I think 0.12 is really something like  0.1199999????.

Anmd his is the reason