Hi friends,

I want to ceil the decimal values of my double number.

For Example,  3.08 --> 3.1
4.18 --> 4.2
5.45 --> 5.5

but whe3n i use Math.Ceiling(3.08) it returns 4.0 whereas I want the answer as 3.1
I know we can do it using simple logic of 2-3 lines
but I am looking for an inbulit for it ??
Any ideas?

7 Years
Discussion Span
Last Post by TomW

You want to round to a specific demicial position (not ceiling function). You havent mentioned how/where this value is being displayed/stored to show a specific example.

In a database such as Sql Server, you can set the precision property of your decimal column to one, that will limit the values to 1 place passed the decimal point.

In VB, with a decimal datatype you can not limit the precision but you can format you numeric value for display using the FormatNumber function.

Sub Main()

        Dim decValue As Decimal = 4.18D

        Console.WriteLine("decValue : {0}", decValue)
        Console.WriteLine("Formatted decValue : {0}", FormatNumber(decValue, 1))

    'decValue : 4.18
    'Formatted decValue : 4.2

End Sub

Edited by TomW: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.