Cast as Decimal in PHP

Can not believe I have to ask, Google failed me. Just a future reference type question. How do you cast a property as decimal?

`var (decimal)$price;`

Not sure if this is what you are asking for or not, https://floating-point-gui.de/languages/php/

I guess my question is do i have the correct syntax for casting a property as a decimal? I’m coming from .Net world c# so we always declare the data type.

Since php is duck typed, the type is interpreted and doesn’t get declaration. So the var is not needed like you would use for an open ended declaration in C#

$dec = 1.50;
echo gettype($dec);
// double
Sponsor our Newsletter | Privacy Policy | Terms of Service