Wrox Programmer Forums
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 18th, 2005, 12:11 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default decimal

Can somebody please tell me what is happening here. I am posting a price from a form then putting it into a session.

$_SESSION['item_total'] = $_POST['item_total'];

echo $_POST['item_total'] . "--posted total<br>";
echo $_SESSION['item_total'] . "--session total<br>";

when i write it out this is the result what is happening to the .97
9.97--posted total
9--session total

Thanks in advance
Old November 3rd, 2005, 10:17 PM
Friend of Wrox
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts

The problem is likely you allow php to define your variable types. If the first value that goes into your total is a 1, then the next is a 2.34. The variable may already be dimensioned in a way that doesn't allow the 2.34. Try to explicity define the data types of your variables to allow 9.97 or whaterver is your max value and see if you get different results. It is a lazy (bad) coding practice to allow php to define your variable types for you.

Similar Threads
Thread Thread Starter Forum Replies Last Post
decimal data type all 0's after decimal gobotsoup SQL Server ASP 1 February 28th, 2007 02:32 PM
Two decimal places only pallone Javascript How-To 5 February 2nd, 2005 12:35 AM
Decimal check Nitin_sharma Javascript 4 November 25th, 2004 12:03 PM
Getting decimal value snowydust VB How-To 1 October 18th, 2004 10:25 AM
Formattig Decimal mahulda ASP.NET 1.0 and 1.1 Basics 2 July 24th, 2004 03:17 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.