This repository has been archived on 2024-09-24. You can view files and clone it, but cannot push or open issues or pull requests.
Schule/Nebenfunktionen/Runden.cpp

19 lines
564 B
C++
Raw Permalink Normal View History

2017-04-24 14:34:49 +02:00
#include<iostream>
2017-04-10 21:17:40 +02:00
2017-04-24 14:34:49 +02:00
long double round(long double number, long long digitsAfterDecimalPoint, bool mathematical)
{
short loop = digitsAfterDecimalPoint;
2017-04-10 21:17:40 +02:00
2017-04-24 14:34:49 +02:00
while(loop>0) number *= 10, loop--;
while(loop<0) number /= 10, loop++;
2017-04-10 21:17:40 +02:00
2017-04-24 14:34:49 +02:00
if(number-(long long)number>0.5 || number-(long long)number==0.5 && ((long long)number%2!=0 || mathematical==false)) number++;
2017-04-10 21:17:40 +02:00
2017-04-24 14:34:49 +02:00
number = (long long)number;
while(digitsAfterDecimalPoint>0) number /= 10, digitsAfterDecimalPoint--;
while(digitsAfterDecimalPoint<0) number *= 10, digitsAfterDecimalPoint++;
return(number);
2017-04-10 21:17:40 +02:00
}