FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour ini return only integer when type is numeric
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
ini return only integer when type is numeric
Posted: Fri Aug 03, 2007 07:27 AM
If a numeric value such as 100.50 is stored in an ini file, reading it back will return 100 not 100.50. The decimal part is somehow excluded. The following is the full scenario

1. App.ini contents:
[Balance]
BF_COL_K=6300
BF_COL_L=2473.50


2. The ini is then read in the following way
function readIni()
  local oIni, aBF := array(2)
  INI oIni FILE "c:\app\data\app.ini"
      GET aBF[COL_K] SECTION "Balance" ENTRY "BF_COL_K"  OF oIni DEFAULT 0.00
      GET aBF[COL_L] SECTION "Balance" ENTRY "BF_COL_L"  OF oIni DEFAULT 0.00
  ENDINI
return nil


Instead of 6300 and 2473.50, I'll get 6300 and 2473 :-). How to fix this?

Am using FWH2.8 and the code was tested on an XP machine

Thank you
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
ini return only integer when type is numeric
Posted: Fri Aug 03, 2007 07:39 AM

Hua,

the TIni-class does not support floating-point values, but you can save and read these value as a string and then convert it back to numeric with Val().

kind regards

Stefan
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
ini return only integer when type is numeric
Posted: Fri Aug 03, 2007 09:43 AM
Thanks for the reply Stefan :-) . Initially I was surprised because I thought if TIni class was able to correctly read/set variable type such as date and logical then surely a numeric type would've been handled correctly also.

My initial workaround was to modify my readIni() to the following (saveIni() seems to be working as expected):
function readIni() 
  local oIni, aBF := array(2) 
  INI oIni FILE "c:\app\data\app.ini" 
      GET aBF[COL_K] SECTION "Balance" ENTRY "BF_COL_K"  OF oIni DEFAULT ""
      GET aBF[COL_L] SECTION "Balance" ENTRY "BF_COL_L"  OF oIni DEFAULT ""
  ENDINI 
  aeval(aBF,{|x,ele| aBF[ele] := val(x)}
return nil


But later, I changed the TIni:Get() method the following way and revert back my changes to readIni().
     .
     .
if Empty( ::cIniFile )
   uVar = GetProfString( cSection, cEntry, cValToChar( uDefault ) )
   if cType == "N"
      uVar := val(uVar)
   endif
else
   uVar = GetPvProfString( cSection, cEntry, cValToChar( uDefault ),;
                           ::cIniFile )
   if cType == "N"
      uVar := val(uVar)
   endif
endif
     .
     .


Seems to be working fine so far
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour

Continue the discussion