Link to home
Create AccountLog in
Visual Basic.NET

Visual Basic.NET

--

Questions

--

Followers

Top Experts

Avatar of Rowel Virgo
Rowel Virgo🇵🇭

VB.NET, SQL, Datagridview Rounding-off Value in column
User generated image
Hi,

I have this from mySQL data server, and I want to remove the decimal. How to round off this column in datagridview, please help and TIA

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Kevin CrossKevin Cross🇺🇸

You can set the format via the DataGrid CellStyle property.
https://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.cellstyle(v=vs.110).aspx

I can show a sample little later but working on a project for now and hoping this helps you until someone else jumps in.

Avatar of Pawan KumarPawan Kumar🇮🇳

You can the same in SQL and .net

Cast or Format column...

SELECT
CAST ( ColumName AS BIGINT )
From yourtable

select cast (21.2432 as int )
select format(21.2333 ,'#')

.Net..

  Int(lnumber)
ToString("column")

Avatar of Rowel VirgoRowel Virgo🇵🇭

ASKER

Hi, instead of changing it on datagridview, since I want to display it in label, I put this code to round off the value but I need a separator for a value ( , ) comma.

Example 5900 make it 5,900

        conn.Open()
        Dim rd = cmd.ExecuteReader
        If rd.Read = True Then
            Label60.Text = rd(1).ToString()
            myDA.Dispose()
        End If

        Dim a As Single
        Dim b As Double = Convert.ToDouble(Label60.Text)
        a = Math.Round(b)
        Label60.Text = a & " MB"
        conn.Close()

Open in new window


User generated image

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of Pawan KumarPawan Kumar🇮🇳

Please try this -

Format function ..

Format( a , "c")

Avatar of Rowel VirgoRowel Virgo🇵🇭

ASKER

User generated image
Where is the Php came from? :)

Avatar of Pawan KumarPawan Kumar🇮🇳

try printing your column with and without format .

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Rowel VirgoRowel Virgo🇵🇭

ASKER

        Dim a As Single
        Dim b As Double = Convert.ToDouble(Label60.Text)
        a = Math.Round(b)
        Label60.Text = Format(a, "c") & " MB"

Open in new window


Is "C" stands for currency?

ASKER CERTIFIED SOLUTION
Avatar of Pawan KumarPawan Kumar🇮🇳

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of Rowel VirgoRowel Virgo🇵🇭

ASKER

Ooooo I got it!

        Label60.Text = Format(a, "0,000") & " MB"

Open in new window


Avatar of Pawan KumarPawan Kumar🇮🇳

Cool...format .!!

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

Visual Basic.NET

Visual Basic.NET

--

Questions

--

Followers

Top Experts

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,