Copyright ©2005  Department of Computer & Information Science Using Number & Math Objects.

Slides:



Advertisements
Similar presentations
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 ◦
Advertisements

1 COMP 110 Static Methods and Variables Tabitha Peck M.S. March 24, 2008 MWF 3-3:50 pm Philips 367.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: Numeric Data *Variables *Numeric data.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 3: Parameters, Return, and Interactive Programs with Scanner.
Numerical Data Recitation – 01/30/2009
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-2: Return; double ; System.out.printf reading: 3.2, 3.5, 4.4 videos: Ch.
CS180 Recitation 3. Lecture: Overflow byte b; b = 127; b += 1; System.out.println("b is" + b); b is -128 byte b; b = 128; //will not compile! b went out.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Functions Part I.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-2: Return; double ; System.out.printf reading: 3.2, 3.5, 4.4 videos: Ch.
© T Madas. Add zero and negative integers Add fractions and decimals which can be represented by fractions Add imaginary numbers Real Numbers ( ) Integers.
Computers and Scientific Thinking David Reed, Creighton University Functions and Randomness 1.
Working with Numbers parseInt() and parseFloat() Math.round() Other Math object functions isNaN() toFixed()
Section 1.1 Numbers and Their Properties.
Using Object-Oriented JavaScript CST 200- JavaScript 4 –
JavaScript Part 2 – Page 1 of 35CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: JavaScript Part 2.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Variable Declaration  It is possible to declare multiple variables of the same data type on the same line.  Ex. double hours, rate, total;  Variables.
1 Number Types  Every value in Java is either: 1.a reference to an object or 2.one of the eight primitive types  eight primitive types: a.four integer.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
Chapter 3.  Traditionally, programming languages have assigned different types of data for different types of numbers.  In many languages, there may.
Introduction An exponent is a quantity that shows the number of times a given number is being multiplied by itself in an exponential expression. In other.
CSC Programming I Lecture 5 August 30, 2002.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Mt. Rushmore, South Dakota CSE 114 – Computer Science I Static Methods andVariables.
More on Objects. Goals By the end of this unit you should … … be able to identify selected String properties … be able to identify and use selected String.
Java Program Components Java Keywords - Java has special keywords that have meaning in Java. - You have already seen a fair amount of keywords. Examples.
Keeping it Neat: Functions and JavaScript Source Files Chapter 7.
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.
Copyright ©2005  Department of Computer & Information Science Introducing Dialogue Windows.
Math Class Part of the Java.lang package. This package is from object so you do not have to import the lang package. Static: Math Class is static.
Numbers © Copyright 2014, Fred McClurg All Rights Reserved.
Basic Data Types Numbers (integer and floating point)‏ Strings (sequences of characters)‏ Boolean values (true/false)‏
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Copyright ©2005  Department of Computer & Information Science JavaScript Modularity.
Lesson 6 Selection Structures. Example program //This will convert a numeric grade into a letter grade import TerminalIO.KeyboardReader; public class.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 5 JavaScript.
CSCE 102 – Chapter 11 (Performing Calculations) CSCE General Applications Programming Benito Mendoza Benito Mendoza 1 By Benito Mendoza.
The Math Class Methods Utilizing the Important Math Operations of Java!
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
1 Java Library Lecture 9 by Dr. Norazah Yusof. 2 Java Library Java has pre-defined classes that consist of the basic language classes in Java (organized.
XP Tutorial 2 New Perspectives on JavaScript, Comprehensive1 Working with Operators and Expressions Creating a New Year’s Day Countdown Clock.
COMP 110 Static variables and methods Luv Kohli October 29, 2008 MWF 2-2:50 pm Sitterson 014.
Hazırlayan:Emin BORANDAĞ 2/17/ Numerik Değerler Kullanımı Integers are considered accurate up to 15 digits. Try it function myFunction() { var x.
ICS 3U Math Class. ActionScript 3 – Math Class Rounding ceil – closest integer >= number (rounds up) floor – closest integer
JavaScript and Ajax (JavaScript Functions) Week 5 Web site:
COMPUTER PROGRAMMING I Objective 7.04 Apply Built-in Math Class Functions.
Copyright 2011 by Pearson Education Building Java Programs Chapter 3 Lecture 3-2: Return values, Math, and double reading: 3.2,
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
Lecture 5: java.lang.Math, java.lang.String and Characters Michael Hsu CSULA.
CS 115 Lecture 5 Math library; building a project Taken from notes by Dr. Neil Moore.
Chapter 4 Mathematical Functions, Characters, and Strings 1.
Chapter 4 Mathematical Functions, Characters, and Strings
Math class Random() method Floor method Top-level parseInt function
Math Class Your favorite class!.
Chapter 4 Mathematical Functions, Characters, and Strings
SEEM4570 Tutorial 05: JavaScript as OOP
Chapter 3 Methods.
Chapter 4: Mathematical Functions, Characters, and Strings
The Math class The java.lang.Math class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square.
Chapter 2 Section 3-C.
JavaScript Basics Stephen Delaney
Numbers.
Chapter 5 Methods.
Building Java Programs
Using Built In Objects Kevin Harville.
Today in COMP 110 Brief static review The Math Class Wrapper Classes
Introduction An exponent is a quantity that shows the number of times a given number is being multiplied by itself in an exponential expression. In other.
Using java libraries CGS3416 spring 2019.
Working with Numbers parseInt() and parseFloat() Math.round()
Ch 5 : Mathematical Functions, Characters, and Strings
Presentation transcript:

Copyright ©2005  Department of Computer & Information Science Using Number & Math Objects

Copyright ©2005  Department of Computer & Information Science Goals By the end of this lecture you should … Be able to identify and program with intrinsic methods of JavaScript's Number class.Be able to identify and program with intrinsic methods of JavaScript's Number class. Be able to identify and program with intrinsic properties of JavaScript's Math class.Be able to identify and program with intrinsic properties of JavaScript's Math class. Be able to identify and program with intrinsic functions of JavaScript's Math class.Be able to identify and program with intrinsic functions of JavaScript's Math class.

Copyright ©2005  Department of Computer & Information Science Number Types JavaScript doesn't distinguish among the different number types. We create new Number objects using the Number constructor method:JavaScript doesn't distinguish among the different number types. We create new Number objects using the Number constructor method: var intNum1 = new Number(5150); var fltNum2 = new Number( );

Copyright ©2005  Department of Computer & Information Science Number.toFixed() Method Number.toFixed() returns a number with a specified number places after the decimal point.Number.toFixed() returns a number with a specified number places after the decimal point. Rounding applies, using these rules:Rounding applies, using these rules: –If a digit is >= 5, then we round up –If a digit is < 5, then we round down If the number has fewer decimal places than the requested decimal places, JavaScript will add zeroes.If the number has fewer decimal places than the requested decimal places, JavaScript will add zeroes.

Copyright ©2005  Department of Computer & Information Science Take the next few minutes to examine the file called usingNumbers_01.html.

Copyright ©2005  Department of Computer & Information Science Number.toString() Method The Number.toString() converts a numeric value to a string type.The Number.toString() converts a numeric value to a string type. Use Number.toString() to output numeric values.Use Number.toString() to output numeric values.

Copyright ©2005  Department of Computer & Information Science parseInt() Function parseInt() takes a value and converts that value to a number. Specifically, it converts the value to an integer (whole number).parseInt() takes a value and converts that value to a number. Specifically, it converts the value to an integer (whole number). We can then assign the converted value to a number variable.We can then assign the converted value to a number variable.

Copyright ©2005  Department of Computer & Information Science parseFloat() Function parseFloat() takes a value and converts that value to a number. Specifically, it converts the value to a floating point number (number with a fractional value).parseFloat() takes a value and converts that value to a number. Specifically, it converts the value to a floating point number (number with a fractional value). We can then assign the converted value to a number variable.We can then assign the converted value to a number variable.

Copyright ©2005  Department of Computer & Information Science isNaN() Function The isNaN() ("not a number") intrinsic function allows us to determine if a value is a numeric type or JavaScript can convert that value to a Number.The isNaN() ("not a number") intrinsic function allows us to determine if a value is a numeric type or JavaScript can convert that value to a Number. Returns true if JavaScript cannot convert to a Number and false if it can convert the value to a Number.Returns true if JavaScript cannot convert to a Number and false if it can convert the value to a Number.

Copyright ©2005  Department of Computer & Information Science Take the next few minutes to examine the file called isNaN_01.html.

Copyright ©2005  Department of Computer & Information Science The Math Object JavaScript provides programmers with a convenient way to use common mathematical tasks and properties.JavaScript provides programmers with a convenient way to use common mathematical tasks and properties. JavaScript groups those tasks and properties into the Math object. Unlike String, Number and other classes, we don't need to create and instance of the Math object in order to use its attributes and functions.JavaScript groups those tasks and properties into the Math object. Unlike String, Number and other classes, we don't need to create and instance of the Math object in order to use its attributes and functions.

Copyright ©2005  Department of Computer & Information Science Math.PI Property The Math.PI property returns the constant value of Π (Pi).The Math.PI property returns the constant value of Π (Pi). You can use Math.PI for calculating the circumference or area of a circle.You can use Math.PI for calculating the circumference or area of a circle.

Copyright ©2005  Department of Computer & Information Science Take the next few minutes to examine the file called usingMath_01.html.

Copyright ©2005  Department of Computer & Information Science Math.abs() Function The Math.abs() function returns the absolute value of a given value (how far the number is from zero).The Math.abs() function returns the absolute value of a given value (how far the number is from zero).

Copyright ©2005  Department of Computer & Information Science Take the next few minutes to examine the file called usingMath_02.html.

Copyright ©2005  Department of Computer & Information Science Math.ceil() Function The Math.ceil() function returns the smallest integer greater than or equal to a given value.The Math.ceil() function returns the smallest integer greater than or equal to a given value. The method always rounds up, towards 0.The method always rounds up, towards 0.

Copyright ©2005  Department of Computer & Information Science Take the next few minutes to examine the file called usingMath_03.html.

Copyright ©2005  Department of Computer & Information Science Math.floor() Function The Math.floor() function returns the nearest integer less than or equal to a given value.The Math.floor() function returns the nearest integer less than or equal to a given value. The method always rounds down, away from 0.The method always rounds down, away from 0.

Copyright ©2005  Department of Computer & Information Science Take the next few minutes to examine the file called usingMath_04.html.

Copyright ©2005  Department of Computer & Information Science Math.round() Function Rounds a given value to the nearest integer, using the following rules:Rounds a given value to the nearest integer, using the following rules: –If a digit is >= 5, then we round up –If a digit is < 5, then we round down

Copyright ©2005  Department of Computer & Information Science Take the next few minutes to examine the file called usingMath_05.html.

Copyright ©2005  Department of Computer & Information Science Math.max() Function The Math.max() function returns the largest number, given a set of multiple numbers.The Math.max() function returns the largest number, given a set of multiple numbers. Separate the numeric arguments with commas.Separate the numeric arguments with commas.

Copyright ©2005  Department of Computer & Information Science Take the next few minutes to examine the file called usingMath_06.html.

Copyright ©2005  Department of Computer & Information Science Math.min() Function The Math.min() function returns the smallest number, given a set of multiple numbers.The Math.min() function returns the smallest number, given a set of multiple numbers. Separate the numeric arguments with commas.Separate the numeric arguments with commas.

Copyright ©2005  Department of Computer & Information Science Take the next few minutes to examine the file called usingMath_07.html.

Copyright ©2005  Department of Computer & Information Science Math.pow() Function The Math.pow() function returns the result of an exponential expression, given a base and an exponent.The Math.pow() function returns the result of an exponential expression, given a base and an exponent. The base is the first argument and the exponent is the second.The base is the first argument and the exponent is the second.

Copyright ©2005  Department of Computer & Information Science Take the next few minutes to examine the file called usingMath_08.html.

Copyright ©2005  Department of Computer & Information Science Math.sqrt() Function The Math.sqrt() function returns the square root of a given value.The Math.sqrt() function returns the square root of a given value.

Copyright ©2005  Department of Computer & Information Science Take the next few minutes to examine the file called usingMath_09.html.

Copyright ©2005  Department of Computer & Information Science Math.random() Function Math.random() produces a psuedo-random number, between 0 and 1.Math.random() produces a psuedo-random number, between 0 and 1. We usually need to scale the number (multiply by an integer factor) and round it to obtain a whole number.We usually need to scale the number (multiply by an integer factor) and round it to obtain a whole number.

Copyright ©2005  Department of Computer & Information Science Take the next few minutes to examine the file called usingMath_10.html.

Copyright ©2005  Department of Computer & Information Science Summary JavaScript provides programmers with Number methods to adjust the display of Number data types.JavaScript provides programmers with Number methods to adjust the display of Number data types. JavaScript allows programmers to use Math object properties & functions without instantiating the Math class.JavaScript allows programmers to use Math object properties & functions without instantiating the Math class.