Recent

Author Topic: [SOLVED] About $ and Cents - Dbf Level 7  (Read 414 times)

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 276
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
[SOLVED] About $ and Cents - Dbf Level 7
« on: October 04, 2024, 10:57:19 pm »
I'm at a part on a project designing Proposals and Sales Orders.  I designed the database with TDbf Level 7.  I'm looking for a suggestion on handling money value fields.  Project Est. and Commission.  Actually the display and save fine as long as I don't enter Cents, i.e. 500.58. Stores in the table field value and changes as you enter to 501.
Should I or can I changes these field from Float to Currency?
« Last Edit: October 05, 2024, 05:14:23 pm by 1HuntnMan »

Fibonacci

  • Hero Member
  • *****
  • Posts: 594
  • Internal Error Hunter
Re: About $ and Cents - Dbf Level 7
« Reply #1 on: October 04, 2024, 11:06:05 pm »
Store money values in cents

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 276
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: About $ and Cents - Dbf Level 7
« Reply #2 on: October 04, 2024, 11:44:03 pm »
So, the DataField is PRICE (FLOAT). Decimals is 2 and DisplayFormat is $0.00.  If I key in 55.25 and tab to the next field is displays $56.00.
so you are saying to store as .5525 correct?

Fibonacci

  • Hero Member
  • *****
  • Posts: 594
  • Internal Error Hunter
Re: About $ and Cents - Dbf Level 7
« Reply #3 on: October 05, 2024, 12:01:43 am »
I dont know much about Tdbf, but if this database doesnt have data type like DECIMAL in MySQL then just use ftLargeInt I guess, then multiply your money value by 100 and save; then read and divide by 100, so you have no floating point errors.

55.25 = 55.25 * 100 = 5525, no floats

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 276
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: About $ and Cents - Dbf Level 7
« Reply #4 on: October 05, 2024, 03:37:26 pm »
Okay, that makes sense.  I've been thinking of just converting this app to SQLite but it would be quite an overhaul.  I used TDbf because this system will probably never be more than a 2-3 users, mostly 1 user because it's a Photography Mgt. System for photographers. Thanks for the wake up call! Take care ...

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 276
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: About $ and Cents - Dbf Level 7
« Reply #5 on: October 05, 2024, 03:39:00 pm »
Yes, also I had these fields setup as Float.

wp

  • Hero Member
  • *****
  • Posts: 12457
Re: About $ and Cents - Dbf Level 7
« Reply #6 on: October 05, 2024, 04:03:14 pm »
I'm at a part on a project designing Proposals and Sales Orders.  I designed the database with TDbf Level 7.  I'm looking for a suggestion on handling money value fields.  Project Est. and Commission.  Actually the display and save fine as long as I don't enter Cents, i.e. 500.58. Stores in the table field value and changes as you enter to 501.
Should I or can I changes these field from Float to Currency?
You could try to add this after opening the dataset (assuming that the field is created as float field):
Code: Pascal  [Select][+][-]
  1.   TFloatField(Dbf1.FieldByName('Value')).Currency := true;

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 276
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: [SOLVED] About $ and Cents - Dbf Level 7
« Reply #7 on: October 06, 2024, 11:42:57 pm »
WP, that's the easy way and works a lot easier than calculating as folks enter data. Thanks

 

TinyPortal © 2005-2018