I need a C rounding function which rounds numbers like MATLAB’s round function. Is there one? If you don’t know how MATLAB’s round function works see this link:
I was thinking I might just write my own simple round function to match MATLAB’s functionality.
Thanks,
DemiSheep
If there isn’t a
round()function in the standard library, you could, if dealing with floating-point numbers, arbitrarily evaluate each value, analyze the number in the place after the place you want to round to, check to see if it’s greater, equal-to, or less-than 5; Then, if the value is less than 5, you canfloor()the number you’re ultimately looking at. If the value of the digit after the place you’re rounding to is 5 or greater, you can proceed to having the functionfloor()the number being evaluated, then add 1.I apologize for any inefficiency tied to this.