Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)   Spam!  
Old August 4th, 2015, 08:01 AM
beingchinmay
Guest
 
Posts: n/a
Default How To Convert Numbers to Strings in PHP?

In a string context, PHP will automatically convert any numeric value to a String. Here is a PHP script examples:

Quote:
<?php
print(-1.3e3);
print("
");
print(strlen(-1.3e3));
print("
");
print("Price = $" . 99.99 . "
");
print(1 . " + " . 2 . " = " . 1+2 . "
");
print(1 . " + " . 2 . " = " . (1+2) . "
");
print(1 . " + " . 2 . " = 3
");
print("
");
?>
This script will print:
-1300
5
Price = $99.99
3
1 + 2 = 3
1 + 2 = 3

The print() function requires a string, so numeric value -1.3e3 is Automatically converted to a string "-1300". The concatenation operator (.) also requires a string, so numeric value 99.99 is automatically converted to a string "99.99". Expression (1 . " + " . 2 . " = " . 1+2 . "") is a little bit interesting. The result is "3" because concatenation operations and addition operation are carried out from left to right. So when the addition operation is reached, we have "1 + 2 = 1"+2, which will cause the string to be converted to a value 1
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert list numbers to static text AlisonCan Word VBA 2 November 4th, 2014 09:40 AM
Convert Numbers to Words hasankelepir Classic ASP Basics 5 October 1st, 2007 07:15 AM
HOW TO USE STRINGS,ARRAYS AND VARIABLES IN PHP jhan316 Beginning PHP 1 July 25th, 2006 07:17 PM
how can i convert strings into integers amahja56 C++ Programming 2 February 27th, 2004 05:27 PM
How can i convert english numbers to arabic number zahidpervaiz Classic ASP Databases 0 December 30th, 2003 05:51 AM



All times are GMT -4. The time now is 05:30 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.