Your problem is that modf
returns the fractional part, not an integer representing the fractional part. The value returned is always less than one and then when assigned to an int
it gets truncated down to 0.
Maybe you wanted to multiply the return by 1000: mod = modf(number, &dmod) * 1000.0;