C# Truncate Method


Use the Truncate method in C# to remove all the numbers after decimal places.

Let’s say the following is our number −

20.35M

To remove the numbers after decimal places, use Truncate() −

decimal.Truncate(20.35M)

Let us see the comple code −

Example

using System;
using System.Linq;

class Demo {
   static void Main() {
      decimal dc = 20.35M;
      Console.WriteLine(dc.Truncate(val));
   }
}

Updated on: 22-Jun-2020

242 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements