TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to VBNET

VB.NET Math.Ceiling and Floor: Double Examples

Use the Math.Ceiling and Math.Floor methods to compute ceiling and floors of Doubles.
Math.Ceiling, Floor. Often numbers need to be manipulated. We can round a number upwards to the nearest integer (with a ceiling function), or down with a floor function.
With VB.NET methods, these functions are available without any development work. We invoke Math.Ceiling and Floor, often with Doubles with fractional parts.Double
Ceiling example. To begin we use the Math.Ceiling function. We pass in Double values and Ceiling returns a Double. Ceiling always changes a fractional value to be the higher integer.

And: With negative and positive numbers, this is not changed. The ceiling of -1.23 is -1.

VB.NET program that computes ceiling, uses Math.Ceiling Module Module1 Sub Main() ' Ceiling returns the next highest integer if a fraction part exists. Dim result As Double = Math.Ceiling(1.23) Console.WriteLine("CEILING 1.23: " + result.ToString) Dim result2 As Double = Math.Ceiling(-1.23) Console.WriteLine("CEILING -1.23: " + result2.ToString) Dim result3 As Double = Math.Ceiling(1) Console.WriteLine("CEILING 1: " + result3.ToString) End Sub End Module Output CEILING 1.23: 2 CEILING -1.23: -1 CEILING 1: 1
Floor example. With floor, we change a number with a fractional part to be the lower integer. Even a number like 1.99 is changed to 1. And integers are left unchanged.
VB.NET program that computes floor, uses Math.Floor Module Module1 Sub Main() ' Floor changes a number to the lower integer if a fraction part is present. Dim floor As Double = Math.Floor(1.99) Console.WriteLine("FLOOR 1.99: " + floor.ToString) Dim floor2 As Double = Math.Floor(-1.99) Console.WriteLine("FLOOR -1.99: " + floor2.ToString) End Sub End Module Output FLOOR 1.99: 1 FLOOR -1.99: -2
A summary. Ceiling and Floor are important functions in the .NET Framework. We rarely need to implement these mathematical methods—we use the reliable ones contained in the Framework.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf