length for decimals in mysql

  • DavyDuke17
  • Graduate
  • Graduate
  • DavyDuke17
  • Posts: 166

Post 3+ Months Ago

I want to have a decimal number in a mysql database which displays a number like .455 . It has 3 places after the decimal places, and no numbers before it. So I believe the proper length for it would be 3,3 right? Well, I put that in phpmyadmin and it is automatically changing it to 4,3 so that there is a 0 before. So the number would end up being 0.455 instead. Is there a way I can fix this, possibly use php to take the 0's out as I display them?
  • DavyDuke17
  • Graduate
  • Graduate
  • DavyDuke17
  • Posts: 166

Post 3+ Months Ago

Any help?..., do you understand my question?
  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Posts: 456
  • Loc: Dhaka, Bangladesh

Post 3+ Months Ago

What version of Mysql you are using?
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

Once you have the value in a php variable you could maybe use something like strstr to get rid of the leading 0:

PHP Code: [ Select ]
<?php
 
$var = 0.455;
 
$var = strstr($var, '.');
 
echo "var = $var";
 
?>
  1. <?php
  2.  
  3. $var = 0.455;
  4.  
  5. $var = strstr($var, '.');
  6.  
  7. echo "var = $var";
  8.  
  9. ?>

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 134 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.