briant Posted September 16, 2006 Share Posted September 16, 2006 How can I get rid of the 0's in front of a number? Thank you Link to comment https://forums.phpfreaks.com/topic/20977-how-do-i-turn-000123-to-123/ Share on other sites More sharing options...
Daniel0 Posted September 16, 2006 Share Posted September 16, 2006 number_format($number);intval($number);Pick one :) Link to comment https://forums.phpfreaks.com/topic/20977-how-do-i-turn-000123-to-123/#findComment-93034 Share on other sites More sharing options...
briant Posted September 16, 2006 Author Share Posted September 16, 2006 Thank you. I just figured out another way too:$num = $num+0; // so it would turn into a numberbut I guess your way is more correct, thanks again.btw, intval don't really work because for some reason:echo intval(042); // 34 Link to comment https://forums.phpfreaks.com/topic/20977-how-do-i-turn-000123-to-123/#findComment-93037 Share on other sites More sharing options...
Daniel0 Posted September 16, 2006 Share Posted September 16, 2006 [code]<?php$number = '000123';echo number_format($number)."\n";echo intval($number);?>[/code] outputs [code]123123[/code] for me... Link to comment https://forums.phpfreaks.com/topic/20977-how-do-i-turn-000123-to-123/#findComment-93045 Share on other sites More sharing options...
Barand Posted September 16, 2006 Share Posted September 16, 2006 [code]<?phpecho intval(042); // 34echo '<br>';echo intval('042'); // 42?>042 means treat as an octal number (base 8)'042' string value equal to 42[/code] Link to comment https://forums.phpfreaks.com/topic/20977-how-do-i-turn-000123-to-123/#findComment-93183 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.