CSharp - Rounding real to integral conversions

Introduction

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

Demo

using System;
class MainClass// ww  w  . java  2  s  .  c o m
{
   public static void Main(string[] args)
   {
       double d = 3.9;
       int i = Convert.ToInt32 (d);
       Console.WriteLine(i);
   }
}

Result

Related Topic