Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

decimal
int16
c
c#
communitycreator

What is Decimal.ToInt16() in C#?

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

Decimal.ToInt16() is a C# method to convert a decimal number to its equivalent of a 16-bit signed integer.

Syntax

public static short ToInt16 (decimal d);

Parameters

d: This is the decimal value we want to convert.

Return value

The value returned is the 16-bit integer equivalent of the decimal number d.

Code example

// use System
using System;
// create class
class DecimalToInt16
{
    // main method
    static void Main()
    {
      // create decimal numbers
      decimal d1 = 123.343m;
      decimal d2 = -323.888m;
      decimal d3 = 0.9999m;

      // convert to int16
      // and print results
      Console.WriteLine(Decimal.ToInt16(d1));
      Console.WriteLine(Decimal.ToInt16(d2));
      Console.WriteLine(Decimal.ToInt16(d3));
    }
}
Convert decimal values to 16-bit integer values

Explanation

  • Lines 10-12: We create some decimal values d1, d2 and d3.

  • Lines 16-19: We call the Decimal.ToInt16() method on the decimal values we created and print the results to the console.

RELATED TAGS

decimal
int16
c
c#
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring