/*
Demostrar 3 formas de redondear nĂºmeros en C#
@author parzibyte
*/
using System;
class MainClass {
public static void Main (string[] args) {
// Para dedondear de modo que:
// * Mayor o igual que .5 sube
// * Menor que .5 baja
// Usa Math.Round
Console.WriteLine("Round(1.4): {0}", Math.Round(1.1));
Console.WriteLine("Round(1.58): {0}", Math.Round(1.58));
Console.WriteLine("Round(50.9): {0}", Math.Round(50.9));
Console.WriteLine("Round(15.1): {0}", Math.Round(15.1));
// Si quieres forzar el redondeo hacia abajo
// utiliza Math.Floor. Eso hace que tanto .1 hasta .9 bajen
Console.WriteLine("Floor(1.4): {0}", Math.Floor(1.4));
Console.WriteLine("Floor(1.58): {0}", Math.Floor(1.58));
Console.WriteLine("Floor(50.9): {0}", Math.Floor(50.9));
Console.WriteLine("Floor(15.1): {0}", Math.Floor(15.1));
// Si quieres forzar el redondeo hacia arriba
// utiliza Math.Ceiling. Eso hace que tanto .1 hasta .9 suban
Console.WriteLine("Ceiling(1.4): {0}", Math.Ceiling(1.4));
Console.WriteLine("Ceiling(1.58): {0}", Math.Ceiling(1.58));
Console.WriteLine("Ceiling(50.9): {0}", Math.Ceiling(50.9));
Console.WriteLine("Ceiling(15.1): {0}", Math.Ceiling(15.1));
}
}
LyoKICBEZW1vc3RyYXIgMyBmb3JtYXMgZGUgcmVkb25kZWFyIG7Dum1lcm9zIGVuIEMjCiAgQGF1dGhvciBwYXJ6aWJ5dGUKKi8KdXNpbmcgU3lzdGVtOwoKY2xhc3MgTWFpbkNsYXNzIHsKICBwdWJsaWMgc3RhdGljIHZvaWQgTWFpbiAoc3RyaW5nW10gYXJncykgewogICAgLy8gUGFyYSBkZWRvbmRlYXIgZGUgbW9kbyBxdWU6CiAgICAvLyAqIE1heW9yIG8gaWd1YWwgcXVlIC41IHN1YmUKICAgIC8vICogTWVub3IgcXVlIC41IGJhamEKICAgIC8vIFVzYSBNYXRoLlJvdW5kCiAgICBDb25zb2xlLldyaXRlTGluZSgiUm91bmQoMS40KTogezB9IiwgTW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