callumb
callumb

Reputation: 189

php - casting a decimal to negative

this is probably ridiculously simple but I'm not sure how to do this properly and couldn't find anything - if I have a positive decimal number, e.g 0.04, what's the best way to cast this to a negative value in PHP?

Upvotes: 1

Views: 5682

Answers (1)

Marc B
Marc B

Reputation: 360922

$var = 0.04;

$neg = -$var; // easiest
$neg = -1 * $var; // bit more explicit
$neg = 0 - $var; // another version

Upvotes: 8

Related Questions