Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be 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.

Jim
Lv 7
Jim asked in Science & MathematicsMathematics · 7 years ago

math function to shift fractional digits left of decimal point?

I need a math function that can shift the digits to the right of the decimal point onto the left side of the decimal point. I don't know if one exists. is there one? what is it? where can I find documentation on it?

does it have a symbol instead of a function?

I would prefer a function or something I can implement as a function if possible.

really what I am trying to do is figure out the number of fractional digits, and I have (ttcalc):

ceil(log( 1+int(abs(frac(511.))) ;10)/log(10;10))

but it is failing miserably. tried 10^x just throwing stuff around to see what might work.

Update:

my function should work for 511 which should render 0, and for 511.2 which should render 1, and for 511.111 should should render 3. I already have a function for handling all positive integers: numIntegerDigits=ceil(log(abs(n)+1;10)/log(base;10))

just not sure how I can "if-then-else" it in a calculator for the 0 case for it to return 1. I am sure this caqn be reworked for frac

it is going into http://jesusnjim.com/programming/calculating-numbe...

Update 2:

you can think of this another way: zappiing the decimal point and everything to the left of it, but using a math function to do it.

Update 3:

the whole point of this is to calculate the length of the number using math where possible, but not with string or number length functions (which would be based on what I am designing). in C++, besides std::ostringstream, the only thing you have is math..

something I can do with the HP-50g calculator, math.h in c++, or other computer language without conversion to strings and back using math and possibly either the ternary operator (?:) or an if else statement is acceptable.

1 Answer

Relevance
  • Anonymous
    7 years ago
    Favorite Answer

    In Excel, I would find the length of the number, then use FIND to locate the decimal point, then it's simple arithmetic, subtract the location with "." from the length.

    Here's another way to do it. Is it ok to drop any trailing 0's, so that 5.123 gives 3, and 5.123000 also gives 3?

    Here's pseudocode:

    x is the number.

    xmult = x

    count = 0

    do while xmult <> int(xmult)

    xmult = xmult * 10

    count = count + 1

    loop

    Explanation: Keep multiplying by 10 until you get an integer. The number of times it takes is the number of characters to the right of the decimal point.

    Source(s): Lots of problem solving in Excel and use of VBA
Still have questions? Get your answers by asking now.