Strange problems on decimals - dangerous bug !!

User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Re: Strange problems on decimals - dangerous bug !!

Post by Marco Turco »

Tried your code but I always got error.

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

Code: Select all | Expand


#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
User avatar
rhlawek
Posts: 194
Joined: Sun Jul 22, 2012 7:01 pm

Re: Strange problems on decimals - dangerous bug !!

Post by rhlawek »

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
User avatar
sambomb
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: Strange problems on decimals - dangerous bug !!

Post by sambomb »

Marco Turco wrote:Tried your code but I always got error.

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

Code: Select all | Expand


#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
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Re: Strange problems on decimals - dangerous bug !!

Post by Marco Turco »

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

Marco Turco
SOFTWARE XP LLP
User avatar
sambomb
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: Strange problems on decimals - dangerous bug !!

Post by sambomb »

Try this now...
I included Set Decimals 20, Set Exact On, extra debugs to trace the value of nTest_Decimals

Code: Select all | Expand



#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
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Re: Strange problems on decimals - dangerous bug !!

Post by Marco Turco »

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
hmpaquito
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Strange problems on decimals - dangerous bug !!

Post by hmpaquito »

Marco,

Please try so:

Code: Select all | Expand


...
nTest_Decimals :=oQry:aData[1,7]

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


Regards
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Strange problems on decimals - dangerous bug !!

Post by James Bott »

Marco,

Did you ever find a solution?

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