FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Strange problems on decimals - dangerous bug !!
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Strange problems on decimals - dangerous bug !!
Posted: Mon Jan 19, 2015 03:33 PM
Tried your code but I always got error.

sambomb wrote:Change the name of the var, nTest_Decimals := 3

Code (fw): Select all Collapse
#include "fivewin.ch"

procedure start()
Local nTest_Decimals := 3

oSQLite := TSQLiteServer():New( "test.sql" )
If oSQLite:lError
msgStop( "error" )
RETURN
EndIf

cQuery:="SELECT * from t_tables;"
oQry:=oSQLite:Query(cQuery)
nTest_Decimals :=oQry:aData[1,7]
oQry:End()
oSQLite:End()

msginfo(nTest_Decimals ) && return 3
msginfo(valtype(nTest_Decimals )) && return N

msginfo(str(88.456,10,3)) && return 88.456
msginfo(str(88.456,10,nTest_Decimals )) && RETURN 88 !!!



return
function gettemppath()
return("")
Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 195
Joined: Sun Jul 22, 2012 07:01 PM
Re: Strange problems on decimals - dangerous bug !!
Posted: Mon Jan 19, 2015 04:14 PM

I have an off topic question. Where did/does the TSQLiteServer() class come from? I've searched high and low and have not yet come across this.

Thanks in advance.

Robb

Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: Strange problems on decimals - dangerous bug !!
Posted: Mon Jan 19, 2015 07:13 PM
Marco Turco wrote:Tried your code but I always got error.

sambomb wrote:Change the name of the var, nTest_Decimals := 3

Code (fw): Select all Collapse
#include "fivewin.ch"

procedure start()
Local nTest_Decimals := 3

oSQLite := TSQLiteServer():New( "test.sql" )
If oSQLite:lError
msgStop( "error" )
RETURN
EndIf

cQuery:="SELECT * from t_tables;"
oQry:=oSQLite:Query(cQuery)
nTest_Decimals :=oQry:aData[1,7]
oQry:End()
oSQLite:End()

msginfo(nTest_Decimals ) && return 3
msginfo(valtype(nTest_Decimals )) && return N

msginfo(str(88.456,10,3)) && return 88.456
msginfo(str(88.456,10,nTest_Decimals )) && RETURN 88 !!!



return
function gettemppath()
return("")



What error?

All I did is replace nDecimals by nTest_Decimals
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Strange problems on decimals - dangerous bug !!
Posted: Mon Jan 19, 2015 08:24 PM

For error I mean that msginfo(str(88.456,10,nTest_Decimals )) Always return 88

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: Strange problems on decimals - dangerous bug !!
Posted: Tue Jan 20, 2015 10:37 AM
Try this now...
I included Set Decimals 20, Set Exact On, extra debugs to trace the value of nTest_Decimals
Code (fw): Select all Collapse
#include "fivewin.ch"

procedure start()
Local nTest_Decimals := 3, nBkpDecimals := -999

   Set Decimals to 20
   Set Exact on

   oSQLite := TSQLiteServer():New( "test.sql" )

   If oSQLite:lError
      msgStop( "error" )
      RETURN
   EndIf

   cQuery:="SELECT * from t_tables;"
   oQry:=oSQLite:Query(cQuery)
   nBkpDecimals := nTest_Decimals
   nTest_Decimals :=oQry:aData[1,7]

   If nTest_Decimals == nBkpDecimals
       MsgInfo("Identical values")
   else
       MsgInfo("Compare decimals values")

       If AllTrim(Str(nTest_Decimals,25,20)) != AllTrim(Str(nBkpDecimals,25,20))
           MsgInfo(AllTrim(Str(nTest_Decimals,25,20)),"nTest")
           MsgInfo(AllTrim(Str(nBkpDecimals,25,20)),"nBkp")
      else
           MsgInfo("Equal strings")
       end


   End

   oQry:End()
   oSQLite:End()

   msginfo(nTest_Decimals )
   msginfo(valtype(nTest_Decimals ))

   msginfo(str(88.456,10,3)) && return 88.456
   msginfo(str(88.456,10,nTest_Decimals )) && RETURN 88 !!!

return

function gettemppath()
return("")
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Strange problems on decimals - dangerous bug !!
Posted: Tue Jan 20, 2015 06:52 PM

Hi sambomb,
i did your test. Identical value but it return always 88.

You can download source and executable from http://109.228.12.120/softwaredistribut ... /test3.zip

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Strange problems on decimals - dangerous bug !!
Posted: Tue Jan 20, 2015 09:00 PM
Marco,

Please try so:

Code (fw): Select all Collapse
...
nTest_Decimals :=oQry:aData[1,7]

nTest_Decimals := Val( Str(nTest_Decimals, 10))               //  <---- New
...


Regards
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Strange problems on decimals - dangerous bug !!
Posted: Thu Jan 29, 2015 12:00 AM

Marco,

Did you ever find a solution?

It looks like hmpaquito's idea might work. Did you try it?

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion