Is it possible to change the numbers of a rounded number?
I would need a number rounded to one decimal number:
1.333333 -> 1.3
0.666666 -> 0.6
Is there any (easy) way to do this?
integer=round(decimal);
float roundNumber(float k, int places){
int i;
for(i=1; i<=places; i++){ //inflate the number
k*=10;
}
k=round(k); //round
for(i=1; i<=places; i++){
k/=10; //deflate the number
}
return k;
}
float roundNumber(float k, int places){
int i;
k*=pow(10, i);
k=round(k); //round
k/=pow(10,i); //deflate the number
return k;
}
Users browsing this forum: No registered users and 1 guest