My assumption is that you just want to display this variable with a decimal point (maybe the variable measures microseconds and you want to display in seconds), and not actually manipulate the variable with a floating point (since you already indicated that floating point operations not available in kernel space).
In this case, do not consider this problem as a conversion from a long integer to a floating point - instead, consider it as a string manipulation problem, especially since your input to strtol is a string.
In pseudo code, if your input and output are separate lines:
void insertDecimalPoint(char const * strSrc, char * strDest, int maxlength) { 1. find the length of strSrc 2. if length <= 6, then write a prefix of zeros like '0.000' to strDest and then copy the source string to the destination 3. else, copy the first (length - 6) digits, then add a decimal point '.', then copy the rest of the source to the destination. }
Alternatively, if you have input as a long integer val , a string like
whole = val / 1e6; fraction = val - whole * 1e6; printf("%d.%06d", whole, fraction);
will do the right thing.
source share