Php – Math functions.

Slides:



Advertisements
Similar presentations
Chapter 4 Methods F Introducing Methods –Benefits of methods, Declaring Methods, and Calling Methods F Passing Parameters –Pass by Value F Overloading.
Advertisements

Line Drawing Algorithms
Building Java Programs
1 MATH METHODS THAT RETURN VALUES. 2 JAVA'S MATH CLASS.
Return values.
Arithmetic in Pascal (2) Arithmetic Functions Perform arithmetic calculations Gives an argument to the function and it returns the result.
Maths & Trig, Statistical functions. ABS Returns the absolute value of a number The absolute value of a number is the number without its sign Syntax ◦
1 DATA ABSTRACTION: USER DEFINED TYPES AND THE CLASS.
Sample Test 1 Question. A pattern of binary digits can be interpreted in several different ways. Show how the pattern translates using each of.
BASIC FUNCTIONS OF EXCEL. Addition The formula for addition is: =SUM( insert cells desired to sum up ) This returns the sum of the selected cells.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 3: Parameters, Return, and Interactive Programs with Scanner.
Assignment Operators =, +=, *= A += B means (A+B) --->A or A = (A+B) Similarly true for -=, *=, /=, and %=. The basic rule is from right to left. Never.
Numbers. Number Conversion Convert – Binary number to decimal numbers – Octal numbers to decimal numbers – Hexadecimal to decimal numbers Convert – Decimal.
Decimal Addition What is going on? (carry) (subtract the base)
Number System Conversions Lecture L2.2 Section 2.3.
= 9 = 8 = 12 = 19 = 2 = 3 = 17 = 5 = 11 = 5.
6-1 Percent Percent: a ratio that compares a number to 100
Introduction to programming Language C, Data Types, Variables, Constants. Basics of C –Every program consists of one or more functions and must have main.
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
Chapter 4 Numbers. Python Program Structure Python programs consist of: Modules Statements Expressions Objects.
D ATA T YPE. NUMBERS A number is an immutable type – means that changing or updating its value result in a newly allocated object. There are several types.
MATH AND RANDOM CLASSES.  The need for random numbers occurs frequently when writing software.  The Random class, which is part of the java.util class,
COMPUTER PROGRAMMING I Objective 7.03 Apply Built-in Math Class Functions Image taken from:
CSC Programming for Science Lecture 7: Math Functions.
Math With Java The Math Class. First, A Quick Review of Math Operators in Java Primitive Data type in Java that represent numbers: Primitive Data type.
CMSC 1041 Functions II Functions that return a value.
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
Introduction As programmers, we don’t want to have to implement functions for every possible task we encounter. The Standard C library contains functions.
Basics and arrays Operators:  Arithmetic: +, -, *, /, %  Relational:, >=, ==, !=  Logical: &&, ||, ! Primitive data types Byte(8), short(16), int(32),
Php – Math functions. FunctionDescription abs()Returns the absolute value of a number ceil()Returns the value of a number rounded upwards to the nearest.
Module-E- Libraries1/49 Module E- Standard Libraries Input and Validation Formatted Output Library Functions.
Data Analysis: Spreadsheets ICT iGCSE. 14.1: Creating a data model.
Computer Science: A Structured Programming Approach Using C1 4-5 Standard Functions C provides a rich collection of standard functions whose definitions.
PHY 107 – Programming For Science. Announcements  Lectures may not cover all material from readings  Material that is most difficult or challenging.
NR 322: Raster Analysis I Jim Graham Fall 2008 Chapter 7.
Jozef Goetz, Converting numbers 1.Converting from the base 2, 5, 8 and 16 numbers to the base 10 number See all a.s for the next slides 2. Converting.
Creating and Using Class Methods. Definition Class Object.
ICS 3U Math Class. ActionScript 3 – Math Class Rounding ceil – closest integer >= number (rounds up) floor – closest integer
160 as a product of its prime factors is 2 5 x 5 Use this information to show that 160 has 12 factors.
Absolute Value and Step Functions (2.4.2) November 10th, 2015.
COMPUTER PROGRAMMING I Objective 7.04 Apply Built-in Math Class Functions.
Recursion It is a process of calling the same function itself again and again until some condition is satisfied. Syntax: func1() { ……….. func1(); }
FUNCTIONS The parts of a function In order to work correctly, a function must be written a specific way, which is called the syntax. The basic syntax for.
Chapter INTRODUCTION Data Types and Arithmetic Calculations.
Find LCM Least Common Multiple of 3 and 5: List the Multiples of each number, The multiples of 3 are 3, 6, 9, 12, 15, 18,... etc The multiples of 5 are.
CSE 110: Programming Language I Afroza Sultana UB 1230.
T/F  The following code will compile without error. int x = 3, y = 4, z = 5; double k = 3.4; cout
Math class Random() method Floor method Top-level parseInt function
Mathematical Functions
Functions, Part 2 of 2 Topics Functions That Return a Value
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Introduction to Programming
Binary, Octal and Hex Numbers Copyright Thaddeus Konar
Binary, Octal and Hex Numbers Copyright Thaddeus Konar
Binary, Octal and Hex Numbers Copyright Thaddeus Konar
Using Free Functions Chapter 3 Computing Fundamentals with C++
Numerical Functions & Tricks
Objective - To round decimals to a specified place value.
There are 10 types of people of people in this world…
4TC00 Model-based systems engineering 2.2 Types and values
Absolute Value and Step Functions (2.4.2)
CHAPTER 3: String And Numeric Data In Python
Rounding off (Outcome).
COMPUTER PROGRAMMING SKILLS
Remember the 10 types of people of people in this world…
Using Excel to do number system conversion
Computer Science 1 Review and finish Number base conversion
Objective 7.03 Apply Built-in Math Class Functions
Lecture 37 – Practice Exercises 9
Lecture 37 – Practice Exercises 9
Presentation transcript:

php – Math functions

常用數學函數 Function Description abs() Returns the absolute value of a number ceil() Returns the value of a number rounded upwards to the nearest integer floor() Returns the value of a number rounded downwards to the nearest integer is_nan() Returns true if a value is not a number lcg_value() Returns a pseudo random number in the range of (0,1) max() Returns the number with the highest value of two specified numbers min() Returns the number with the lowest value of two specified numbers pow() Returns the value of x to the power of y mt_rand() Returns a random integer using Mersenne Twister algorithm rand() Returns a random integer round() Rounds a number to the nearest integer sqrt() Returns the square root of a number

亂數 float lcg_value () int mt_rand(min, max) int rand(min, max) 產生介於0與1之浮點亂數 int mt_rand(min, max) int rand(min, max) 產生介於min與max之整數亂數 <?php echo lcg_value()."<br/>"; echo rand(1,49)."<br/>"; echo mt_rand(1,49)."<br/>"; ?>

四捨五入 <?php echo round(3.4); // 3 echo round(3.5); // 4 echo round(3.6); // 4 echo round(3.6, 0); // 4 echo round(3.6); // 4 echo round(1.95583, 2); // 1.96 echo round(1241757, -3); // 1242000 echo round(5.045, 2); // 5.05 echo round(5.055, 2); // 5.06 ?>

二, 八, 十, 十六進位轉換 base_convert() Converts a number from one base to another bindec() Converts a binary number to a decimal number decbin() Converts a decimal number to a binary number dechex() Converts a decimal number to a hexadecimal number decoct() Converts a decimal number to an octal number hexdec() Converts a hexadecimal number to a decimal number octdec() Converts an octal number to a decimal number