Re: Splitting double into integers

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Well, first off, how are you going to deal with trailing zeros? Note that "2
and 34" is the same as "2 and 340". I'll assume you don't want trailing
zeros.

You say you can get it to where you've got "2 and .34". Ok, you're more than
half way there. You want to know the number of digits in the fractional
part, and then multiply it by 10 to that power. To get the number of digits
is easy:

int Digit_Count( double value )
{
return (value.ToString())->Length ;
}

Note this will include the decimal point, so subtract one from this. So, you
want to do this (using your example):

34 = .34 * pow( 10, Digit_Count( .34 ) - 1 ) ;

Now just use variables where the "34" and ".34" are...

[==P==]

"H.B." <HB@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:98806582-91E9-44B4-A88D-8909A3E742A9@xxxxxxxxxxxxxxxx
> Hi,
>
> How can I split Double into two integers like the following example :
>
> 2.34 -> 2 and 34 (I dont want the modf() result that gives 2 and 0.34)
>
> Hugo


.



Relevant Pages

  • Re: discrete math help.
    ... > no repeating digits. ... > I'm stumped if the digits can't repeat. ... > I can find ALL the 6-digit integers with no leading zeros and no ... Prev by Date: ...
    (sci.math)
  • Re: Unix Need Help with auto incrementing a field between delimiter. Awk?
    ... > delimited field with padding of 9 digits with leading zeros. ... When is your homework due? ... Prev by Date: ...
    (comp.unix.admin)
  • Re: require 10 digits
    ... Eventually the invoice numbers will be 6 digits with 4 leading zeros(once we ... them stored with the leading zeros. ... Prev by Date: ...
    (microsoft.public.access.tablesdbdesign)
  • Re: SUMPRODUCT with Wildcard
    ... You need to be careful when using the LEFT function in this way. ... significant digits, and will exclude leading zeros. ... Prev by Date: ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Problem Importing from an Excel spread sheet to an Access 2003 table.
    ... display 5 digits with a single command? ... displayed as 5 digits and 5 digits only. ... >1) Modify the Excel sheet before import by prefixing an ... leading zeros. ...
    (microsoft.public.access.externaldata)