Home > php, Programming > PHP: removed trailing zeros from numeric strings (code illustration)

PHP: removed trailing zeros from numeric strings (code illustration)

<?php
	$nums=array('1.0', '2.300', '4', '5.9000');

	echo "Original format:\n";
	foreach($nums as $num) {
		echo "$num\n";
	}

	echo "\nTrailing zeros removed:\n";
	foreach($nums as $num) {
		echo ($num+0)."\n";
	}

Output:
Original format:
1.0
2.300
4
5.9000

Trailing zeros removed:
1
2.3
4
5.9

Advertisements
Categories: php, Programming
  1. Anon Ü. Mus
    March 26, 2015 at 10:25 am

    BIG THANK YOU :)

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: