+ Reply to Thread
Results 1 to 3 of 3

Thread: Remove this warning : conversion from 'double' to 'int', possible loss of data

  1. #1

    Remove this warning : conversion from 'double' to 'int', possible loss of data

    I have below code:

    Code:
    double dValue = 10 ;
    
    int nValue = dValue ;

    Compiler says: warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data

    How best we can remove this warning?

    Thanks.

  2. #2
    Senior Member
    Join Date
    Feb 2012
    Posts
    109
    There are two common solution to this issue.

    Example:

    Code:
    double dValue = 10 ;
    
    //PART 1: C-Style Casting
    int nValue = (int) dValue ;
    
    //C++ style
    int nValue1 = static_cast<int> (dValue) ;
    Note
    In C++, it is recommended that you should use C++ style casting.

  3. #3
    Thanks buddy. I got it.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

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