locked
How to Work with Decimal in Visual C++? RRS feed

  • Question

  • Hi,

     

    I am using Visual C++ to work with SQL Server. The problem is that there is no corresponding data type like decimal/numeric in VIsual C++. Which kind of C++ variable should I put the field value to after retrieving it from SQL Server database?

     

    Thanks

    Friday, August 3, 2018 3:28 AM

Answers

  • Hi,

     

    I am using Visual C++ to work with SQL Server. The problem is that there is no corresponding data type like decimal/numeric in VIsual C++. Which kind of C++ variable should I put the field value to after retrieving it from SQL Server database?

     

    Thanks

    Hi chcw,

    For Data Type Mappings between SQL Server and Visual C++, you could refer to:

    SQL: SQL and C++ Data Types (ODBC)

    Best Regards,

    Will


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Olaf HelperMVP Friday, August 3, 2018 5:50 AM
    • Marked as answer by chcw Saturday, August 4, 2018 1:41 AM
    Friday, August 3, 2018 3:50 AM
  • If you only want to display the data, string of some sort would be the best choice. If you want to run calculations, you would have to use double. Which means that you can get issue because of the impreciseness of double.

    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

    • Marked as answer by chcw Saturday, August 4, 2018 1:41 AM
    Friday, August 3, 2018 7:21 AM
  • Hi, Will

    Thanks. However, such a mapping seems have problems. If decimal is mapped to CString, then I will not perform mathematic calculation after the mapping. Also if date is mapped to CTime, then since SQL Server data range is from year 1 to 9999, while CTime is only for 1970 to 3000, most of the values cannot mapped properly?

    Hi chcw,

    If you mean that you would like to do some mathematic calculation in Front-end application (Visual C++), you could choose related data conversion function to convert them into specific number type in Visual C++.

    For how to choose specific function for conversion, you could submit your questions to Visual C++ forum for professional help.

    Best Regards,

    Will



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by chcw Saturday, August 4, 2018 1:41 AM
    Friday, August 3, 2018 7:57 AM

All replies

  • Hi,

     

    I am using Visual C++ to work with SQL Server. The problem is that there is no corresponding data type like decimal/numeric in VIsual C++. Which kind of C++ variable should I put the field value to after retrieving it from SQL Server database?

     

    Thanks

    Hi chcw,

    For Data Type Mappings between SQL Server and Visual C++, you could refer to:

    SQL: SQL and C++ Data Types (ODBC)

    Best Regards,

    Will


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Olaf HelperMVP Friday, August 3, 2018 5:50 AM
    • Marked as answer by chcw Saturday, August 4, 2018 1:41 AM
    Friday, August 3, 2018 3:50 AM
  • Hi,

     

    I am using Visual C++ to work with SQL Server. The problem is that there is no corresponding data type like decimal/numeric in VIsual C++. Which kind of C++ variable should I put the field value to after retrieving it from SQL Server database?

     

    Thanks

    Hi chcw,

    For Data Type Mappings between SQL Server and Visual C++, you could refer to:

    SQL: SQL and C++ Data Types (ODBC)

    Best Regards,

    Will


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Hi, Will

    Thanks. However, such a mapping seems have problems. If decimal is mapped to CString, then I will not perform mathematic calculation after the mapping. Also if date is mapped to CTime, then since SQL Server data range is from year 1 to 9999, while CTime is only for 1970 to 3000, most of the values cannot mapped properly?

    Friday, August 3, 2018 7:10 AM
  • If you only want to display the data, string of some sort would be the best choice. If you want to run calculations, you would have to use double. Which means that you can get issue because of the impreciseness of double.

    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

    • Marked as answer by chcw Saturday, August 4, 2018 1:41 AM
    Friday, August 3, 2018 7:21 AM
  • Hi, Will

    Thanks. However, such a mapping seems have problems. If decimal is mapped to CString, then I will not perform mathematic calculation after the mapping. Also if date is mapped to CTime, then since SQL Server data range is from year 1 to 9999, while CTime is only for 1970 to 3000, most of the values cannot mapped properly?

    Hi chcw,

    If you mean that you would like to do some mathematic calculation in Front-end application (Visual C++), you could choose related data conversion function to convert them into specific number type in Visual C++.

    For how to choose specific function for conversion, you could submit your questions to Visual C++ forum for professional help.

    Best Regards,

    Will



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by chcw Saturday, August 4, 2018 1:41 AM
    Friday, August 3, 2018 7:57 AM