You could use math.floor(x) From the Lua Reference Manual: Returns the largest integer smaller than or equal to x.

Division of integers in Java

Converting the output is too late; the calculation has already taken place in integer arithmetic. You need to convert the inputs to double: Note that you don’t actually need to convert both of the inputs. So long as one of them is double, the other will be implicitly converted. But I prefer to do both, for symmetry.

Printf width specifier to maintain precision of floating-point value

I recommend @Jens Gustedt hexadecimal solution: use %a. OP wants “print with maximum precision (or at least to the most significant decimal)”. A simple example would be to print one seventh as in: But let’s dig deeper … Mathematically, the answer is “0.142857 142857 142857 …”, but we are using finite precision floating point numbers. … Read more

Using floats with sprintf() in embedded C

Since you’re on an embedded platform, it’s quite possible that you don’t have the full range of capabilities from the printf()-style functions. Assuming you have floats at all (still not necessarily a given for embedded stuff), you can emulate it with something like: You’ll need to restrict how many characters come after the decimal based … Read more

Float and double datatype in Java

The Wikipedia page on it is a good place to start. To sum up: float is represented in 32 bits, with 1 sign bit, 8 bits of exponent, and 23 bits of the significand (or what follows from a scientific-notation number: 2.33728*1012; 33728 is the significand). double is represented in 64 bits, with 1 sign bit, 11 bits of … Read more