12,076,586 members (49,340 online)
Rate this:
See more:
when I enter the number 3.4 on the form in C # windows application into a database sql server 2005,, a number that is printed is 3.44445556.

how to change the number 3.44445556 to 3.4?
Posted 22-Mar-12 20:49pm
SAKryukov 23-Mar-12 2:23am

Sounds strange... Float accuracy is low, but not that bad... :-)
Did you run it all under debugger, check the value immediately before getting a string representation? Could be some bug. By the way, float is used rarely, as the accuracy is often not enough, usually people use double... All System.Math is written in double only.
--SA
digimanus 23-Mar-12 4:26am

better show the code that creates the error

since the value is 4,4 in stead of 4.4 the error is found easily. You have to use globalization to prevent this. And you try to convert ToInt32() in stead of ToFloat()
SAKryukov 23-Mar-12 11:32am

Of course. How "4,4" can represent integer?
--SA

Rate this:

## Solution 1

Simply use `Math.Round` function.

Function usage:
`Math.Round(decimal d,int dec);`
`double num = Math.Round(3.44445556, 1);`
v3
Shahin Khorshidnia 23-Mar-12 7:05am

My +5
Praveen Kullu 23-Mar-12 7:09am

d = 3.44445556 here.
Rate this:

## Solution 2

```Declare @flt as Float
Set @flt = 3.44445556
Select round(@flt,1)
```
OUTPUT :3.3999999999999999

`AND IF YOU USE MONEY DATATYPE `

```Declare @flt as MONEY
Set @flt = 3.44445556
Select round(@flt,1)
```

OUTPUT : 3.40

BETTER TO USE MONEY DATATYPE

Shahin Khorshidnia 23-Mar-12 7:06am

my +5
(__Aaron__) 24-Mar-12 2:06am

nice!

Top Experts
Last 24hrsThis month
 Richard MacCutchan 420 Sergey Alexandrovich Kryukov 360 Jochen Arndt 350 OriginalGriff 305 F-ES Sitecore 225
 Dave Kreskowiak 2,836 OriginalGriff 2,805 Richard MacCutchan 2,174 CPallini 1,607 CHill60 1,379