PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




Double datatype in PHP


Tutorials »Php »

Topic

How to define a double variable and assign value?



Explanation

The Double data type is used to specify floating point numbers.

When you are declaring double variable, you can declare as given below

double $variable;

where double denotes the type of the variable.

The range of floating point numbers in PHP is equivalent to the range of the double type in C, Double can range from 1.7E-308 to 1.7E+308. A double may be expressed either as a regular number with a decimal point or in scientific notation.

For example:

$var=0.017;
$var=17.0E-3

You can also declare variable without datatype, in such case PHP will try to determine type of variable based on the value hold by that variable. Below I have declared a variable without its type.

$variable =99.5;

Here the variable hold the floating point value so it is of type double.

If you want to get a type of a variable, you can use gettype() function.
Example:

print gettype($variable);

Above code will print type double because floating point value is assigned to that variable. If you want to permanently change type of variable then you can use typecast function such as settype() to change the type of the variable. If you want to change type temporary, eg just for use in an expression then you will use type casting.





Other Links

web hosting