I know, I know, one of the big advantages of PHP is that the variables in PHP don't take typecasting but instead any variable can hold any data. Thing is, for something I'm trying right now I need the ability to cast. I'm trying to add together financial values drawn from a database, which means they're all floating-point with two significant digits after the decimal. Problem is, actually doing addition on them seems to deal with integer addition; if the values both end in .*0, then any zeroes after the decimal point are eliminated from the value before it gets displayed on the resulting page. Is there any way in PHP to code for a financial numeric typecast, or am I going to have to hack around it with stringlength comparisons and artifical trailing zeroes?

Recommended Answers

All 2 Replies

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.