B
Bubba
Greetings to all,
I'm searching for cheap, quick and easy rounding function in C, but (there
had to be but!) without any libraries. In other words, is there a sane
mathematical (or any other, for that matter) way that can be implemented
in C and round arbitrary number of decimal places them to desired decimal
places?
So, basically, something like this:
double round (double number, unsigned decimalPlaces) {
/* some magic here */ }
Basic point is to make it portable for everything from Motorola 68000 to
embedded ARM or latest gaming x64 CPU.
I tried doing it myself but couldn't even begin being puzzled about
determining number of decimal places in the first place, let alone doing
any rounding with them.
Also did some Googling research but found only solutions with strings and
similar tricks (which I was acquainted with) or written in C++. Appreciate
any help or hint.
TIA!
I'm searching for cheap, quick and easy rounding function in C, but (there
had to be but!) without any libraries. In other words, is there a sane
mathematical (or any other, for that matter) way that can be implemented
in C and round arbitrary number of decimal places them to desired decimal
places?
So, basically, something like this:
double round (double number, unsigned decimalPlaces) {
/* some magic here */ }
Basic point is to make it portable for everything from Motorola 68000 to
embedded ARM or latest gaming x64 CPU.
I tried doing it myself but couldn't even begin being puzzled about
determining number of decimal places in the first place, let alone doing
any rounding with them.
Also did some Googling research but found only solutions with strings and
similar tricks (which I was acquainted with) or written in C++. Appreciate
any help or hint.
TIA!