NeoSoft Support Forum Forum Index  Your source for Plug-Ins, sample publications, source code and more...

Source Language:
Translate to:

NeoSoft Support Forum
NeoSoft Community Support Forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   SmartFeedSmartFeed   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

About SQL Statement
Goto page 1, 2  Next
 
Post new topic   printer-friendly view   Reply to topic    NeoSoft Support Forum Forum Index -> NeoBookDBPro
View previous topic :: View next topic  
Author Message
carlos torres
NeoBooker


Joined: 02 May 2005
Posts: 223
Location: Pamplona, Colombia

PostPosted: Fri Jun 20, 2008 6:41 am    Post subject: About SQL Statement Reply with quote

Hi everybody

I'm trying to upgrade an old app developed with dbf to dbp.

When I use this statement with integer values it works fine
Code:

dbpExecSQL "DbList" "UPDATE Db SET Nota6=[#34][Num][#34]" ""


But when [Num] contains any decimal value (real number or single) it has a wierd behavior.

ie. [Num] is 1.6 it shows 1,60000002384186
ie. [Num] is 2.3 it shows 2,29999995231628
ie. [Num] is 3.5 it shows 3.5
ie. [Num] is 3.6 it shows 3,59999990463257
ie. [Num] is 3.7 it shows 3,70000004768372


I just need 1.6 or 3.7 values. Only one decimal on the mantissa.

How can I avoid this kind of results?
I's dbp bug?

I will appreciate any help, TIA

regards
carlost
Back to top
View user's profile Send private message
Wrangler
NeoBooker


Joined: 31 Mar 2005
Posts: 1331
Location: USA

PostPosted: Fri Jun 20, 2008 8:24 am    Post subject: Reply with quote

I have a similar problem with a currency field in Access db:

../ Get total item sales per model
FileLen "[pubdir]products.dat" "[flen]"

Loop "1" "[flen]" "[x]"
FileRead "[pubdir]products.dat" "[x]" "[getproduct]"
dbpQuery "invoicer" "products" "proddesc = [#34][getproduct][#34]"
dbpSum "invoicer" "products" "subtotal" "[total[getproduct]]"
dbpSum "invoicer" "products" "qty" "[[getproduct]sales]"
Math "[totalitems]+[[getproduct]sales]" "" "[totalitems]"
endloop

Brings this result:



It only does it to a couple of them. All the rest display correctly. Don't know if this is related to Carlos problem or not.
_________________
Wrangler
--------------
Before you criticize someone, walk a mile in their shoes. Then when you criticize them you're a mile away and you have their shoes. Surprised - Wrangler

Software made with NeoBook
http://highdesertsoftware.com
Back to top
View user's profile Send private message Visit poster's website
Neosoft Support
NeoSoft Team


Joined: 31 Mar 2005
Posts: 4048
Location: Oregon, USA

PostPosted: Fri Jun 20, 2008 11:17 am    Post subject: Reply with quote

What you need to do is use DBPro's dbpSetFieldProperties action to define the DisplayFormat for the field. This will allow you to customize the number of decimal places, etc.
_________________
NeoSoft Support
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Wrangler
NeoBooker


Joined: 31 Mar 2005
Posts: 1331
Location: USA

PostPosted: Fri Jun 20, 2008 11:25 am    Post subject: Reply with quote

I'm using a currency field. Shouldn't it default to 2 decimal places?
_________________
Wrangler
--------------
Before you criticize someone, walk a mile in their shoes. Then when you criticize them you're a mile away and you have their shoes. Surprised - Wrangler

Software made with NeoBook
http://highdesertsoftware.com
Back to top
View user's profile Send private message Visit poster's website
Neosoft Support
NeoSoft Team


Joined: 31 Mar 2005
Posts: 4048
Location: Oregon, USA

PostPosted: Mon Jun 23, 2008 10:55 am    Post subject: Reply with quote

Wrangler, I think the problem with your numbers is caused by the Math action. In your example, you left the second parameter empty which causes the result to have as many or as few decimal places as it needs. Instead, if you want the result to have exactly two decimal places, you should put "2" in this parameter. For example:

Math "[totalitems]+[[getproduct]sales]" "2" "[totalitems]"
_________________
NeoSoft Support
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Wrangler
NeoBooker


Joined: 31 Mar 2005
Posts: 1331
Location: USA

PostPosted: Mon Jun 23, 2008 11:13 am    Post subject: Reply with quote

The math action totals the number of items, which isn't affected by this. However, I fixed it by adding a math action after the dbpsum:

../ Get total item sales per model
FileLen "[pubdir]products.dat" "[flen]"

Loop "1" "[flen]" "[x]"
FileRead "[pubdir]products.dat" "[x]" "[getproduct]"
dbpQuery "invoicer" "products" "proddesc = [#34][getproduct][#34]"
dbpSum "invoicer" "products" "subtotal" "[total[getproduct]]"
Math "[total[getproduct]]" "2" "[total[getproduct]]"
dbpSum "invoicer" "products" "qty" "[[getproduct]sales]"
Math "[totalitems]+[[getproduct]sales]" "2" "[totalitems]"

endloop

I guess I assumed because I set the field properties for the subtotal field to currency in startup actions:

dbpSetFieldProperties "invoicer" "products" "subtotal" "Alignment=Center;DisplayFormat=#.00"

it would also display as such after the dbpsum. Funny thing is, it did it for all of them but the two.
_________________
Wrangler
--------------
Before you criticize someone, walk a mile in their shoes. Then when you criticize them you're a mile away and you have their shoes. Surprised - Wrangler

Software made with NeoBook
http://highdesertsoftware.com
Back to top
View user's profile Send private message Visit poster's website
Neosoft Support
NeoSoft Team


Joined: 31 Mar 2005
Posts: 4048
Location: Oregon, USA

PostPosted: Mon Jun 23, 2008 11:24 am    Post subject: Reply with quote

dbpSum works outside the constraints of the table, but I suppose it could borrow the field's display format for its result. However, what if the display format includes something that isn't normally part of a number such as a dollar sign? That could mess up any subsequent math actions. For example:

DisplayFormat=$#.00

or

DisplayFormat=£#.00
_________________
NeoSoft Support
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Wrangler
NeoBooker


Joined: 31 Mar 2005
Posts: 1331
Location: USA

PostPosted: Mon Jun 23, 2008 11:30 am    Post subject: Reply with quote

You have a point there. If the $ is included in the field data, it wouldn't work. But it's not stored in there, is it? Can't see how it could sum it up if it was.
_________________
Wrangler
--------------
Before you criticize someone, walk a mile in their shoes. Then when you criticize them you're a mile away and you have their shoes. Surprised - Wrangler

Software made with NeoBook
http://highdesertsoftware.com
Back to top
View user's profile Send private message Visit poster's website
domino
NeoBooker


Joined: 02 Apr 2005
Posts: 287
Location: Notts UK

PostPosted: Tue Jun 09, 2009 5:46 am    Post subject: Reply with quote

I`m having a similar issue with my application

In effect I`ve created a shopping cart and whether I use math or dbprosum I can`t get it to display .00 where a value has no decimal places.. (ie whole £ pounds no pence)

eg: it displays 24 rather than 24.00

(in math mode setting decimal places to either 2 or -1 has no effect.)
Back to top
View user's profile Send private message
dpayer
NeoBooker


Joined: 11 Apr 2005
Posts: 890

PostPosted: Tue Jun 09, 2009 8:27 am    Post subject: Reply with quote

domino wrote:
I`m having a similar issue with my application

In effect I`ve created a shopping cart and whether I use math or dbprosum I can`t get it to display .00 where a value has no decimal places.. (ie whole £ pounds no pence)

eg: it displays 24 rather than 24.00

(in math mode setting decimal places to either 2 or -1 has no effect.)


At the point of making a display, it is no longer needed to be a number (specifically) it is a string. You can do a strsearch for the 'dot' and if it doesn't exist, add a .00 to the string before displaying.

David P
Back to top
View user's profile Send private message Send e-mail AIM Address
domino
NeoBooker


Joined: 02 Apr 2005
Posts: 287
Location: Notts UK

PostPosted: Tue Jun 09, 2009 8:53 am    Post subject: Reply with quote

Quote:
At the point of making a display, it is no longer needed to be a number (specifically) it is a string. You can do a strsearch for the 'dot' and if it doesn't exist, add a .00 to the string before displaying.


Thanks David - I guess that's the pragmatic solution, and what I`ll have to do, but was rather hoping there was a setting lurking somewhere.

Cheers
Dave
Back to top
View user's profile Send private message
David de Argentina
NeoBooker


Joined: 04 Apr 2005
Posts: 926
Location: Buenos Aires, Argentina

PostPosted: Tue Jun 09, 2009 8:56 am    Post subject: Reply with quote

Or...

Use NeoFormatNumber Plugin in order to do a specific format.

You could check this plugin at:

http://www.neosoftware.com/neobook/modules/plugins/singlefile.php?cid=9&lid=54

Greetings from Buenos Aires,
David de Argentina
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Wrangler
NeoBooker


Joined: 31 Mar 2005
Posts: 1331
Location: USA

PostPosted: Tue Jun 09, 2009 8:57 am    Post subject: Reply with quote

For me, the math method works if used right before display or after the sum:

Math "[total]" "2" "[total]"
_________________
Wrangler
--------------
Before you criticize someone, walk a mile in their shoes. Then when you criticize them you're a mile away and you have their shoes. Surprised - Wrangler

Software made with NeoBook
http://highdesertsoftware.com
Back to top
View user's profile Send private message Visit poster's website
domino
NeoBooker


Joined: 02 Apr 2005
Posts: 287
Location: Notts UK

PostPosted: Tue Jun 09, 2009 3:26 pm    Post subject: Reply with quote

Thanks for the replies....

Unfortunately none of them quite deal with the main issue which appears to be the inability of a "currency field" to retain the .00 for whole numbers.

Any of your solutions are fine as workarounds - but mean that the dbpro sum command cannot be used 'as is' if the .00 is required.

For my application it's not a huge issue as I simply reformatted the relevant fields as strings and ran math loops thus enabling the offending .00 results to carry through to the preview, report and the completed orders table.

Cheers
Dave
Back to top
View user's profile Send private message
Neosoft Support
NeoSoft Team


Joined: 31 Mar 2005
Posts: 4048
Location: Oregon, USA

PostPosted: Wed Jun 10, 2009 9:41 am    Post subject: Reply with quote

The following was added to DBPro 1.2 released in January:

Quote:
The value returned by the dbpSum action is now formatted using the calculated field's display format as specified in dbpSetFieldProperties.


So if you set the field's display format with dbpSetFieldProperties that format will be used for the results produced by dbpSum.
_________________
NeoSoft Support
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    NeoSoft Support Forum Forum Index -> NeoBookDBPro All times are GMT - 7 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

Forum content © 2008 NeoSoft Corp. All rights reserved.