1 // Created on: 2002-01-25
3 // Copyright (c) 2002-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 // Lastly modified by :
22 // +---------------------------------------------------------------------------+
23 // ! doneux ! Creation ! 06/17/02! %V%-1!
24 // +---------------------------------------------------------------------------+
30 #include <OSD_Real2String.ixx>
32 #if defined(HAVE_STDLIB_H) || defined(WNT)
36 //=======================================================================
37 //function : OSD_Real2String
39 //=======================================================================
41 OSD_Real2String::OSD_Real2String():
44 float F1 = (float ) 1.1 ;
47 sprintf(str,"%.1f",F1) ;
48 // printf("%s\n",str) ;
49 myLocalDecimalPoint = str[1] ;
52 //=======================================================================
53 //function : RealToCString
55 //=======================================================================
57 Standard_Boolean OSD_Real2String::RealToCString(const Standard_Real theReal,
58 Standard_PCharacter& theString) const
62 if (sprintf(theString,"%.17e",theReal) <= 0)
63 return Standard_False ;
65 // Suppress "e+00" and unsignificant 0's
67 if ((p = strchr(theString,'e'))) {
68 if (!strcmp(p,"e+00"))
70 for (q = p-1 ; *q == '0' ; q--) ;
73 if (*q != myLocalDecimalPoint) q++ ;
80 return Standard_True ;
83 //=======================================================================
84 //function : CStringToReal
86 //=======================================================================
88 Standard_Boolean OSD_Real2String::CStringToReal(const Standard_CString theString,
89 Standard_Real& theReal)
93 if (! theString) return Standard_False;
95 // Get the decimal point character in the string (if any)
96 if (!myReadDecimalPoint) {
97 if (strchr(theString, ',')) myReadDecimalPoint = ',';
98 else if (strchr(theString, '.')) myReadDecimalPoint = '.';
102 const char *str = theString;
104 if (myReadDecimalPoint) {
105 if (myReadDecimalPoint != myLocalDecimalPoint) {
107 // replace the decimal point by the local one
108 if(myReadDecimalPoint != myLocalDecimalPoint &&
109 (p = strchr(theString,myReadDecimalPoint))&& ((p-theString) < 1000) )
111 strncpy(buff, theString, 1000);
112 buff[p-theString] = myLocalDecimalPoint;
118 theReal = strtod(str,&endptr) ;
120 return Standard_False ;
122 return Standard_True;