I have number of type double. double a = 12.00 I have to make it as 12 by removing .00
Please help me
Step 1: Write down the decimal divided by 1. Step 2: Multiply both top and bottom by 10 for every number after the decimal point. (For example, if there are two numbers after the decimal point, then use 100, if there are three then use 1000, etc.) Step 3: Simplify (or reduce) the Rational number.
In the C Programming Language, the modf function splits a floating-point value into an integer and a fractional part. The fraction is returned by the modf function and the integer part is stored in the iptr variable.
The trunc() function rounds x towards zero and returns the nearest integral value that is not larger in magnitude than x. Simply, the trunc() function truncate the value after decimal and returns the integer part only.
Using the modulo ( % ) operator The % operator is an arithmetic operator that calculates and returns the remainder after the division of two numbers. If a number is divided by 1, the remainder will be the fractional part. So, using the modulo operator will give the fractional part of a float.
Well 12
and 12.00
have exactly the same representation as double
values. Are you trying to end up with a double
or something else? (For example, you could cast to int
, if you were convinced the value would be in the right range, and if the truncation effect is what you want.)
You might want to look at these methods too:
Math.Floor
Math.Ceiling
Math.Round
(with variations for how to handle midpoints)Math.Truncate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With