Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Learning Rounding and Truncation from the Maths library
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Collections; namespace Rextester { public class Program { public static void Main(string[] args) { // Learning to round / truncate a float number float myFloat = 23.654586f; Console.WriteLine("original number: 23.654586\n"); Console.WriteLine(string.Format("myFloat.ToString(): {0} (default setting is 5 dec places with rounding)\n",myFloat.ToString())); Console.WriteLine(string.Format("float.ToString(\"F4\"): {0} (has rounding)\n",myFloat.ToString("F4"))); Console.WriteLine("converting a truncated string of a float, back to a float number"); Console.WriteLine(string.Format("float.Parse(float.ToString): {0}\n",float.Parse( myFloat.ToString("F3") ))); // converted to string converted back to float Console.WriteLine("directly rounding off a float number. must include System.Collections class"); Console.WriteLine(string.Format("Math.Round(float,1): {0}",Math.Round( myFloat, 1 ))); Console.WriteLine(Math.Truncate( myFloat)); } } }
run
|
edit
|
history
|
help
0
bc160400236
Binary Search Tree
Get UTC time and offset minutes
Hello Demo
Chris Kasongo Lazarius Mukengeshayi "Entelect BlackJack 21"
Pascal Tringle
Hello World
lala
Math Course: Remainders
Fibonacci series