Type conversion problem RRS feed

  • Question

  • By high-precision data into a low accuracy of data will produce data loss; Low precision convert high-precision won't have a problem. For instance float convert int generates data loss, int convert float won't have a problem. But if a int data a, first converts it into float, then convert int, can with primitive data item, etc? Following cases: Int a = 5; B = a float, Cout < < a - (int) endl; < b, Test, the output is 0. Convert float to convert int with primitive data is equal. A = 2523456789 int, B = a float, Cout < < a - (int) endl; < b, To measure, the output for 21! Not equal to! The plastic float on several to change, change again come back, will not wait! Consulting a master. The reason is that: Data transfer the information when losses include two kinds, one kind is total loss, one kind is precision loss. By int conversion to float could no longer quantity of losses, but the possible loss of precision. Int - > > int, float - after conversion words differ likely. Therefore, a large data after two after conversion has a minute differences.
    • Moved by Tom Li - MSFT Monday, January 31, 2011 5:10 AM (From:SQL Server Security)
    Wednesday, January 19, 2011 5:37 AM


  • Hi kissmen,


    Thanks for your post.

    Since this forum is only for SQL Server and this issue is more related to C++, I would like to recommend that you ask it in related forum and you will get specific support.


    Meanwhile I will move this thread to Off-Topic after 7 days.

    Tom Li
    • Marked as answer by Tom Li - MSFT Monday, January 31, 2011 5:10 AM
    Friday, January 21, 2011 6:28 AM