dflow Posted November 25, 2009 Share Posted November 25, 2009 i have an AVG result it is echoed fine with the decimal point and i want it to be inserted as a double: ($_POST['AVGrating'], "double"), and set in the db as a double but the inserted value in the db is rounded down for example 3.80 is 3.00 any ideas? Link to comment https://forums.phpfreaks.com/topic/182933-why-is-double-getting-roounded/ Share on other sites More sharing options...
Goldeneye Posted November 25, 2009 Share Posted November 25, 2009 Look at the round function in the PHP Manual. Try round($_POST['AVGrating'], 2) Link to comment https://forums.phpfreaks.com/topic/182933-why-is-double-getting-roounded/#findComment-965556 Share on other sites More sharing options...
dflow Posted November 25, 2009 Author Share Posted November 25, 2009 Look at the round function in the PHP Manual. Try round($_POST['AVGrating'], 2) thanks but i dont want it rounded <input type="hidden" name="AVGrating" value="<?php echo sprintf($total); ?>" /> Link to comment https://forums.phpfreaks.com/topic/182933-why-is-double-getting-roounded/#findComment-965559 Share on other sites More sharing options...
Goldeneye Posted November 25, 2009 Share Posted November 25, 2009 PHP automatically rounds decimal numbers to whole-numbers. So you have to use the round function to set how many significant digits you want. Link to comment https://forums.phpfreaks.com/topic/182933-why-is-double-getting-roounded/#findComment-965562 Share on other sites More sharing options...
dflow Posted November 25, 2009 Author Share Posted November 25, 2009 not working Link to comment https://forums.phpfreaks.com/topic/182933-why-is-double-getting-roounded/#findComment-965567 Share on other sites More sharing options...
roopurt18 Posted November 25, 2009 Share Posted November 25, 2009 PHP automatically rounds decimal numbers to whole-numbers. Only in certain contexts. @dflow, you're going to need to show us more code that is relevant to your problem. We need to know how the value is created (or where it's coming from) and see how you're trying to insert it into your database. We'd also need to know the table structure for the table you're inserting into. Link to comment https://forums.phpfreaks.com/topic/182933-why-is-double-getting-roounded/#findComment-965581 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.