Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
36 views

Lecture 26 - PHP (Numbers)

This document discusses numbers in PHP including integers and floating-point numbers. It covers checking if a variable contains a valid number, comparing and rounding floating-point numbers, taking logarithms, generating random numbers, calculating exponents, formatting numbers, and handling very large or small numbers. Functions mentioned include is_float(), is_int(), round(), ceil(), floor(), log(), log10(), exp(), and trigonometric functions. The document provides an introduction to working with different types of numbers in PHP programs.

Uploaded by

Mariam Chuhdry
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Lecture 26 - PHP (Numbers)

This document discusses numbers in PHP including integers and floating-point numbers. It covers checking if a variable contains a valid number, comparing and rounding floating-point numbers, taking logarithms, generating random numbers, calculating exponents, formatting numbers, and handling very large or small numbers. Functions mentioned include is_float(), is_int(), round(), ceil(), floor(), log(), log10(), exp(), and trigonometric functions. The document provides an introduction to working with different types of numbers in PHP programs.

Uploaded by

Mariam Chuhdry
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Web Application

Engineering
Lecture 26
Numbers in PHP
 Everywhere
 Time, Date, Cost, Contants
 In PHP: Integers and floating-point numbers
 Automatically converts from strings to numbers and back
Introduction  1+"1" is 2.
 2.2e–308 - 1.8e308
 BCMath and GMP Liberaries
Checking
Whether a
Variable
Contains a
Valid Number
 5,100?
 Use str_replace()

Checking
Whether a
Variable
Contains a
Valid Number  is_float() ; is_double() ; is_int()
Comparing
Floating-Point
Numbers
 $number = round(2.4)
 $number = ceil(2.4);

Rounding  $number = floor(2.4);


 $final = round($total, 2);
Floating-Point
Numbers  If a number falls exactly between two integers, PHP rounds
away from 0
Operating on a
Series of
Integers
Generating
Random
Numbers
 $log = log(10);
Taking  $log10 = log10(10);
Logarithms  $log2 = log(10, 2);
 To raise e to a power, use exp()
 // $exp (e squared) is about 7.389
 $exp = exp(2);

Calculating
Exponents
Formatting
Numbers
Printing
Correct Plurals
Calculating
Trigonometric
Functions
Handling Very
Large or Very
Small
Numbers
Questions?

You might also like