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
Stacks: Balanced Brackets -final
save bitmap from stream problem
InvokeProgram
Planet-D
Hex-String Encoder/Decoder + Obfuscator by Cuppujeano
t
Test date/time bug
іфи
Hello world
amstrong number