How to apply a data format in the calculated field

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
User avatar
afayez
Posts: 12
Joined: 2020-09-06 15:24
Location: EGYPT
Contact:

How to apply a data format in the calculated field

Post by afayez » 2021-01-11 16:28

Dear,
Good day,

I have a calculated field (Quantity * Price). i tried to make a numbers format 12,345.67 bit it gave an erroe message:

Error checking:
Warning: Skipping calculations for field 'qtn.total': This field can't be a calculated field.
Reason: Fields that have a data format specified can't be calculculated fields (you can apply a data format in the calculation instead)
Finished error checking.
PHP application generation process cancelled by user.


Support please how can apply a data format in the calculation instead.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: How to apply a data format in the calculated field

Post by pbottcher » 2021-01-11 16:41

Hi,

try

FORMAT(FIELDNAME or CALCULATION,2,'YOURLANGUAGENEED')

for what you show it should be standard and you could use

FORMAT(FIELDNAME or CALCULATION,2)
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
afayez
Posts: 12
Joined: 2020-09-06 15:24
Location: EGYPT
Contact:

Re: How to apply a data format in the calculated field

Post by afayez » 2021-01-12 03:45

Thanks

i tried to put {FORMAT( `all_invoices` ,2)} at the end of the formula but it didn't work, can you support

SELECT
SUM(`invoices`.`sum`)
FROM
`projects` LEFT JOIN
`invoices` ON `projects`.`id` = `invoices`.`project_id`
WHERE
`projects`.`id` = '7'

FORMAT( `all_invoices` ,2)

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: How to apply a data format in the calculated field

Post by pbottcher » 2021-01-12 07:01

Hi,

can you try

Code: Select all

SELECT
FORMAT(SUM(`invoices`.`sum`),2)
FROM
`projects` LEFT JOIN
`invoices` ON `projects`.`id` = `invoices`.`project_id`
WHERE
`projects`.`id` = '7'
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1814
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to apply a data format in the calculated field

Post by jsetzer » 2021-01-12 07:09

Additional notes:

Code: Select all

... format(sum(...), 2) ...
https://www.w3resource.com/mysql/mathem ... unded%20up.

Please note that sum(...) returns a numeric value but format(sum(...), 2) returns a string. If you are facing problems, check the data type of that field.

Also, when using the calculated field for subsequent calculations, remember that this is a string now and not a number. Especially when format returns strings containing comma "," or point "." due to locale settings this could lead to follow up miscalculations.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
afayez
Posts: 12
Joined: 2020-09-06 15:24
Location: EGYPT
Contact:

Re: How to apply a data format in the calculated field

Post by afayez » 2021-01-12 07:30

Thanks alot
It worked very well.
but the couloumn sum is not working well. as in the attached photo.
Attachments
2.png
2.png (1.58 KiB) Viewed 2609 times

Post Reply