Converting string to double in ObjectARX

By Virupaksha Aithal

In ObjectARX, you can use acdbDisToF API to convert the string value to a double value. This API also takes different format string input (Decimal/Engineering/Architectural/Fractional) as shown in below code and converts the string to double value.

void convertStringToDouble()
{
    //-1 to use current database units
    int unit = -1;
    // 5 is pr
    double value = 0;
    acdbDisToF(_T("15.0"), unit, &value);
    acutPrintf(_T("double is %fn"), value);
    //for Scientific use 1
    unit = 1;
    acdbDisToF(_T("1.5000000000E+01"), unit, &value);
    acutPrintf(_T("Scientific : %fn"), value);
 
    //for Decimal  use 2
    unit = 2;
    acdbDisToF(_T("15.0000000000"), unit, &value);
    acutPrintf(_T("Decimal  : %fn"), value);
 
    //for Engineering   use 3
    unit = 3;
    acdbDisToF(_T("1'-3.0000000000""), unit, &value);
    acutPrintf(_T("Engineering  : %fn"), value);
 
    //for Architectural use 4
    unit = 4;
    acdbDisToF(_T("1'-3""), unit, &value);
    acutPrintf(_T("Architectural  : %fn"), value);
 
    //for Fractional use 5
    unit = 5;
    acdbDisToF(_T("15"), unit, &value);
    acutPrintf(_T("Fractional   : %fn"), value);
}

Comments

2 responses to “Converting string to double in ObjectARX”

  1. Dhananjay Dixit Avatar
    Dhananjay Dixit

    int unit = -1;
    double value = 0;
    acdbDisToF(_T(“304.80”), unit, &value);
    gives me value = 304.80000000000001
    I am expecting it to be 304.8
    Is this correct?

  2. very educative blog

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading