Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

decimal
uint64
c#
communitycreator

What is the Decimal.ToUInt64() method 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

The Decimal.ToUInt64() method converts the value of the specified decimal to the equivalent 64-bit unsigned integer.

Syntax

public static ulong ToUInt64 (decimal d);

Parameters

d: This is the decimal value that we want to convert to the equivalent 64-bit unsigned integer.

Return value

A UInt64 value is returned. It is a 64-bit unsigned integer equivalent of the specified decimal value.

Code example

// use System
using System;
// create class
class DecimalTOUInt64
{
    // main method
    static void Main()
    {
        // create decimal values
        decimal d1 = 34.5m;
        decimal d2 = 2.4356345m;
        decimal d3 = 10.34m;

        // convert to UInt64
        // and print value
        Console.WriteLine("Value = {0}, type = {1}",
                            Decimal.ToUInt64(d1),
                            Decimal.ToUInt64(d1).GetType());

        Console.WriteLine("Value = {0}, type = {1}",
                    Decimal.ToUInt64(d2),
                    Decimal.ToUInt64(d2).GetType());
        
        Console.WriteLine("Value = {0}, type = {1}",
                    Decimal.ToUInt64(d3),
                    Decimal.ToUInt64(d3).GetType());
    }
}
Convert decimal values to UInt64 in C#

Explanation

  • Lines 10-12: We create variables d1, d2, and d3 of type decimal and assign decimal values to them.

  • Lines 16-26: We convert each value to an unsigned 64-bit integer using the Decimal.ToUInt64() method. Then we print the converted values and their type.

RELATED TAGS

decimal
uint64
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