CSharp - Rounding real to integral conversions

Introduction

To round rather than truncate, use Convert's numerical conversion methods:

Demo

using System;
class MainClass//from  www  . j  a  v  a2 s  . c  om
{
   public static void Main(string[] args)
   {
       double d = 3.9;
       int i = Convert.ToInt32 (d);
       Console.WriteLine(i);
   }
}

Result

Related Topic