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?

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))
        Console.ReadLine()

    'Results
    'decValue : 4.18
    'Formatted decValue : 4.2

End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.