Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Is there a way to multiply any number with integers to get specific digits at specific place values?
For example, let's say I have the number 0.71631. I want to multiply it with an integer so that way I get a number with .001 within it, the rest of the other digits don't matter. Is there a formula to find an integer or integers that do this without brute forcing it?
2 Answers
- ?Lv 72 years agoFavorite Answer
Another way to look at the same question is whether any integer multiple of 71631 will have zeros in the thousands and ten-thousands place, and a one in the hundreds place.
This "brute force" method is tedious for hand calculations, but quite easy to write as a computer routine.
Here's a FORTRAN loop:
DO 10 J = 1 TO 9999
N = 71631*J
K = N/100
Comment: the K will simply be a truncation.
IF MOD(K,1000) .EQ. 1 THEN
WRITE (6,*) 'SUCCESS AT ', J, ' ', N
STOP
ENDIF
10 CONTINUE
WRITE(6,*) 'NO LUCK FOR J < 10000'
END
- D gLv 72 years ago
you are talking about rounding
and or truncating..
0.716 cannot be multiplied by a integer to get less than 0.716
but maybe you mean.. you want 3 digits after the decimal
that is easy
intermediate number = ((number to round) * 10 ^(digits after dec) )+ 0.5
this basically turns the floating point number into a larger number by the amount of the decimals you wish to save ..
you then convert this number into an INTEGER
Integer = intermediate number
then you convert this back to a decimal number
rounded number = ((double) integer) /(10^(digits))
that gives your number rounded
so if you have this number using 3 as digits the steps look like this
intermediate number = 0.71631 * 1000 + 0.5
intermediate number = 716.31 + 0.5 = 716.8
the integer of this is
Integer = 716
then we convert it back
rounded number = 716/1000 = 0.716
NOW this is not completely true because in computers the floating point number is base 2 so it wont be nice and neat all the time but it should be close