PHPRad Classic Initial 2.7.3 Forum

PHPRad Forum => Issues => Topic started by: xela05 on April 24, 2022, 03:49:39 PM

Title: Projeblem when using custum fields
Post by: xela05 on April 24, 2022, 03:49:39 PM
Hello,

I've a table as on the image bellow where I've data from DB with quantity and price.
Them I creat a custom field where I multiply the quantity * price in order to get a total and I used the "format record field" along the columns in order to have them with the € sign.

I now want to have a "Field Footer Expression" on this custom field with the Sum of all the values I previously multiplied.

THE PROBLEM

If the multiplied field is configured as currency the "Field Footer Expression" SUM produces an error, but if it is configured as number I works ok and I can then configure the SUM as currency.
The thing is that I want both - The Costum Field with the multiplication - and the "Field Footer Expression" with the SUM of the multiplication with currency sign.

How can this be achived?
Title: Re: Projeblem when using custum fields
Post by: willvin on April 25, 2022, 09:53:31 AM
@xela05‍ you cannot make a calculation on a string. once the value you are dealing with contains characters other than numbers, it is a string. In other to do calculations with them you need to convert t to an integer, double or float value. You can read more here PHP - How to Convert String to Float? (tutorialkart.com) (https://www.tutorialkart.com/php/php-convert-string-to-float/#:~:text=To%20convert%20string%20to%20float%20using%20PHP%20built%2Din%20function,corresponding%20to%20the%20string%20content.&text=%24float_value%20%3D%20floatval(%20%24string%20)%3B) to understand.
Code: [Select]
$product = (float) $value1 * (float) $value2