Results 1 to 4 of 4

Thread: [RESOLVED] retrieving decimal in floating variable

  1. #1

    Thread Starter
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Resolved [RESOLVED] retrieving decimal in floating variable

    hi,
    How to get the decimal point of the float or doubld variable.
    ex.
    100.23 = .23 or 23
    .12 = .12 or 12

    thanks ,
    Popskie

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: retrieving decimal in floating variable

    There might be a cleaner way, but this should at least get you the result. Just be aware, that you are boud to get small rounding errors here:


    Code:
                float myFloat = 15.12f;
                int myInt = (int)myFloat;
                float myAnswer = myFloat - (float)myInt;


    An other way could be to cast it to string, and then find the . sign and then use SubString.


    - ØØ -

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [RESOLVED] retrieving decimal in floating variable

    That gives you 0.1199999.

    This is equally ugly but gives you 0.12.

    Code:
    float value = 15.12f;
    decimal decimalPart = (decimal) value - (decimal) Math.Floor(value);

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] retrieving decimal in floating variable

    Math.IEEERemainder(someValue, 1)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width