Ir al contenido principal

Javascript Rounding Operations

Learning the different kinds of rounding operations can have many applications. In this article I will explain what each rounding application in JavaScript does. Even though the code may change on different programming languages, they all do the same.

Math.floor();

Rounds the number down 
Examples:
  1. Math.floor(1.5) = 1
  2. Math.floor(2.7) = 2
  3. Math.floor(1.3) = 1

Math.ceil();

Rounds the number up 
Examples:
  1. Math.ceil(1.5) = 2
  2. Math.ceil(2.7) = 3
  3. Math.ceil(1.3) = 2

Math.round();

Rounds the number to the closest integer
Examples:
  1. Math.round(1.5) = 2
  2. Math.round(2.7) = 3
  3. Math.round(1.3) = 1

Comentarios

Entradas más populares de este blog

Counting in Hexadecimal

When searching for how to convert decimal numbers to hexadecimal it may seem like a daunting task. Until you learn about modulo . The easiest way for me to count in Hex is by counting in decimal and converting to Hexadecimal using the modulo operator(like a programmer). First you divide the decimal number by 16 Math.floor() the Division Result Find the Division Remainder using modulo Divide the number of your Division Result by 16 Repeat the previous steps until your Division Result is 0 For this example we will use the decimal number 53 Divide Division Result Division Remainder 53 / 16 Math.floor(3.3125) = 3 53 % 16 = 5 3 / 16 Math.floor(0.1875) = 0 3 % 16 = 3 We take the remainders going from the latest remainder to the one we got first. In this case 3 5 (the order is important). Then we use this table to translate the remainders into hex Decimal value Hex Equivalent 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10...

Get started on animation

I've always been curious about how animations work and how one day I could be able to make one. One day I decided to look for 3d animation courses online and ended up paying for one that was rated as one of the best online courses. Here I leave a list that hopefully might get you get started.     First things first: Download an animation software like the ones listed below(they're entirely free) Blender 3d Pencil2d   Synfig Studio(2d animation)   Take a course that can help you get started: My favorite course from GameDev.tv Blender Enviroment Artist: Create 3d Worlds https://cgboost.com/ Software for texturing: Armor Paint Blender 3d Free PBR textures and HDRIs: ambientCG Poly Haven Textures Websites: 3Dassets.one Share Textures http://texturelib.com/ https://pixabay.com/ https://unsplash.com/ https://www.pexels.com/ Poliigon Textures Textures.com Let your imagination fly     Check out the simple animations that I was able to make after dedicating a couple...