CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #5
    Join Date
    May 2009
    Posts
    23

    Re: identifying integer assigned to double, how to?

    hi,

    This is part of a calculator, right now the input goes into a double value and the result is also a double value, so 2*2 ends up being 4.000..., which is correct but not very pretty. So i need to figure out a way to represent integer results as integers.

    i need to know if the user entered an integer so that i can display the output as an integer without decimal followed by 0s. for instance the result of 2*2 should be displayed as 4 and not 4.000000...,

    the code snippet fails if the value of the decimal part is 0000000000000001 for instance if i store 1.0000000000000001 into doublevar, the if condition fails, why? i dont know yet , i'll have to deal with this once i've figured out how to extract the integer value if the user has entered an integer into the double value.

    how can i extract the integer value from the double variable if the user has entered an integer? sizeof(int) is 4 bytes, sizeof(double) is 8 bytes. i need to extract the integer and then check it for range -2147483648 to 2147483647. If i cast the double value to int explicitly is there any chance i'll lose data?

    thanks again for the replies
    Last edited by austinium; October 22nd, 2009 at 01:11 AM. Reason: added details

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

Featured