Recent

Author Topic: Date and Currency format  (Read 17551 times)

Fossy

  • New Member
  • *
  • Posts: 22
Date and Currency format
« on: March 16, 2006, 06:33:10 am »
Hello friends:

How I can set the Date to format "DD/MM/YYYY" and Currency to "1.234,56"?.

I have export the LC_MONETARY and LC_DATE to es_ES (Spanish) in Linux terminal but I continues viewing the DateEdit in "DD-MM-YY", and Currency in "1,234.56" even if I set the displayformat or floatformat to "#,##0.00".

I think that Lazarus displays the format stored in environment variables (not work in my case), but I will like set the both formats in source code, because when my app run in other computer, if that computer have the environment variables in other language, my app will runs in spanish mode.

Other problem that I have is displaying currency (or float) in TDBEdit . The number stored in the field table is "1.174,33", and TDBEdit shows "8.3E+2" :?... how I can solve it?.

Thanks!!

tech-pro

  • Full Member
  • ***
  • Posts: 173
    • Tech-Pro.net
RE: Date and Currency format
« Reply #1 on: March 16, 2006, 09:26:47 am »
Look at procedure GetFormatSettings in sysutils.pp. That will show you how the runtime routines establish the default settings. I haven't tried in Laz, but in Delphi you can just override these values by setting different format strings.
Julian

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Date and Currency format
« Reply #2 on: March 17, 2006, 12:09:10 am »
Quote from: "Fossy"
Hello friends:

How I can set the Date to format "DD/MM/YYYY" and Currency to "1.234,56"?.



This will use the ShortDateFormat global string variable to format the date:

  FormatDateTime('ddddd', Now)

ShortDateFormat is set automatically based on your locale.

Global character variables ThousandSeparator and DecimalSeparator are also set based on your locale. You can use these indirectly as follows:

Format('%.2n', [1234.56])

For (lots) more information, refer to FPC's rtl.pdf.

If these global variables are not getting set correctly for your locale, post this as a bug on FPC site.

Fossy

  • New Member
  • *
  • Posts: 22
Date and Currency format
« Reply #3 on: March 17, 2006, 03:41:04 am »
Thanks Phil and Tech-Pro:

GetFormatSettings is for restore the defaults locale values, but I was not find doc for override it and set my own defaults.

FormatDateTime is used for format in runtime any parameter passed to this function, but I can't use it for format date in TDBEdits. Get the value in an TDBEdit and put the new format value in it, causes error of validation date (really making this I'm editing the field). FormatDateTime is valid for show an date format in TLabel or TEdit.

ShorDateFormat is valid, but  I set it to "DD/MM/YYYY" and TDBEdits shows "DD-MM-YYYY" (with - and not /).

And Format ('%.2n',[xxxxxx]) is the operation like FormatDateTime, but in Format() we can pass an value specified in [xxxxx], but I can't use it in TDBEdits.

I have set all my locale to es_ES@euro, I have used three ways:

# dpkg-reconfigure locales (and I configure it in graphical mode)
and:
Editing my /etc/locale.gen
# locale-gen
and:
Exporting LANG and LC_CTYPE environment variables, both set to es_ES@euro

All try don't work. I continue seeing in my app the date in "DD-MM-YYYY" and currency in "1,234.56".

Any other ideas?.

Thanks.

tech-pro

  • Full Member
  • ***
  • Posts: 173
    • Tech-Pro.net
Date and Currency format
« Reply #4 on: March 17, 2006, 09:26:06 am »
You have to set DateSeparator to "/". The "/" in the ShortDateFormat mask represents the date separator, it doesn't actually specify it. At least, that's the way it works in Delphi.
Julian

Phil

  • Hero Member
  • *****
  • Posts: 2737
Date and Currency format
« Reply #5 on: March 17, 2006, 05:43:40 pm »
Quote from: "Fossy"
Thanks Phil and Tech-Pro:
All try don't work. I continue seeing in my app the date in "DD-MM-YYYY" and currency in "1,234.56".
Thanks.


Did you try changing global character variables ThousandSeparator and DecimalSeparator? I would assume that TDBEdit would use these too.

Fossy

  • New Member
  • *
  • Posts: 22
Date and Currency format
« Reply #6 on: March 18, 2006, 04:09:16 am »
WOW WOW!!!!

Phil!!!!, that work!!!!!

ThousandSeparator, DecimalSeparator and DateSeparator is solved my problem!! :)

Now only have one problem for resolve (posted in my first message). In TDBEdit the currency (integer or float, I was try both) shows very bad...

I have TDBGrid that it have an float field (Dbase IV), and shows "825,67" correctly because I have set the DisplayFormat property to "#.##0,00", but I have an TDBEdit in the same form linked to the same field and the same datasource, and it shows "8,E+2". Know you why TDBEdit shows bad the value?.

If I set blank the DisplayFormat property in TTable columns, also shows "8,E+2" value. I don't understand why shows it in bad format.

Thank you very much Phil!!!!

Fossy

  • New Member
  • *
  • Posts: 22
Date and Currency format
« Reply #7 on: March 19, 2006, 01:39:45 am »
Problem solved!!

I was not know that the property DisplayFormat of TDBGrid component set the display format directly in TDBF, and all the rest of visual components uses it.

Now I can view the TDBEdits showing float fields correctly :)

Thanks!!!

Anonymous

  • Guest
Date and Currency format
« Reply #8 on: April 06, 2006, 09:37:22 pm »
Hi, name's Tibi.
So for the date to work you must set it to:
DD'/'MM'/'YYYY
Worked for me. Have fun!

 

TinyPortal © 2005-2018