1 // File: OSD_Real2String.cxx
2 // Created: Fri Jan 25 12:58:55 2002
3 // Author: doneux <doneux@samcef.com>
5 const static char sccsid[] = "@(#) OSD_Real2String.cxx %V%-1, 06/17/02@(#)";
6 // Lastly modified by :
7 // +---------------------------------------------------------------------------+
8 // ! doneux ! Creation ! 06/17/02! %V%-1!
9 // +---------------------------------------------------------------------------+
15 #include <OSD_Real2String.ixx>
17 #if defined(HAVE_STDLIB_H) || defined(WNT)
21 //=======================================================================
22 //function : OSD_Real2String
24 //=======================================================================
26 OSD_Real2String::OSD_Real2String():
29 float F1 = (float ) 1.1 ;
32 sprintf(str,"%.1f",F1) ;
33 // printf("%s\n",str) ;
34 myLocalDecimalPoint = str[1] ;
37 //=======================================================================
38 //function : RealToCString
40 //=======================================================================
42 Standard_Boolean OSD_Real2String::RealToCString(const Standard_Real theReal,
43 Standard_PCharacter& theString) const
47 if (sprintf(theString,"%.17e",theReal) <= 0)
48 return Standard_False ;
50 // Suppress "e+00" and unsignificant 0's
52 if ((p = strchr(theString,'e'))) {
53 if (!strcmp(p,"e+00"))
55 for (q = p-1 ; *q == '0' ; q--) ;
58 if (*q != myLocalDecimalPoint) q++ ;
65 return Standard_True ;
68 //=======================================================================
69 //function : CStringToReal
71 //=======================================================================
73 Standard_Boolean OSD_Real2String::CStringToReal(const Standard_CString theString,
74 Standard_Real& theReal)
78 if (! theString) return Standard_False;
80 // Get the decimal point character in the string (if any)
81 if (!myReadDecimalPoint) {
82 if (strchr(theString, ',')) myReadDecimalPoint = ',';
83 else if (strchr(theString, '.')) myReadDecimalPoint = '.';
87 const char *str = theString;
88 if (myReadDecimalPoint) {
89 if (myReadDecimalPoint != myLocalDecimalPoint) {
92 // replace the decimal point by the local one
93 if(myReadDecimalPoint != myLocalDecimalPoint &&
94 (p = strchr(theString,myReadDecimalPoint))&& ((p-theString) < 1000) )
96 strncpy(buff, theString, 1000);
97 buff[p-theString] = myLocalDecimalPoint;
103 theReal = strtod(str,&endptr) ;
105 return Standard_False ;
107 return Standard_True;