Showing posts with label cast. Show all posts
Showing posts with label cast. Show all posts

Wednesday, March 7, 2012

Rounding problem with data conversion

Hi,
I am trying to convert a char column so that I can subtract the values from
another column. I have tried cast and convert, to change it to decimal, but
have found that both methods round values to the nearest whole number.
The column contains money, so this is causing me to lose the pence.
Any help would be greatly appreciated.
Many thanks
PaulI've managed to solve this now, so will close the thread.
The convert worked in the end.
Thanks anyway.
"PaulGodfrey" wrote:

> Hi,
> I am trying to convert a char column so that I can subtract the values fro
m
> another column. I have tried cast and convert, to change it to decimal, b
ut
> have found that both methods round values to the nearest whole number.
> The column contains money, so this is causing me to lose the pence.
> Any help would be greatly appreciated.
> Many thanks
> Paul

Rounding Problem

Hi all,
Is there any function that truncates a decimal numeric without rounding, if
i use cast it rounds the figure but can i don't want that i.e i want it to
be as follows:
23.1238 turns to 23.123 and not 23.124 so it keeps only three decimals as
is
Please advise if there is any function or so
Thanks in advance
Suad
Try
Round(23.1238,3,1)

Rounding decimals for numbers AFTER the AVG func. Please take a l

My query returns numbers to the report, these are already rounded (this is
made to happen in query as they are cast to int).
After I get these integers to my report, I tend to group them, and AVG a
group set. If there is a lot of the numbers in the equation, the total tends
to decimalise to a really ridiculous number (x.xxxxxxxxxxxx). So, I try
putting d or n in the custom format properties for this textbox, I also try a
number of the default formatting options. Even I try to use the <format> tag
in the XML. All to no effect.
The only thing I can think is that I tend to write out a '%' after the
number (to show it's a percentage, it's purely cosmetic). Here is a line of
the AVG function, and how I am using it . I would really appreciate it if
anyone knew what I might be goofing up on here!
=iif(Avg(Fields!DoneIt.Value) = 0, "0%", Avg(Fields!DoneIt.Value) & "%")Did you try just using the following expression:
=Avg(Fields!DoneIt.Value)
and then just use formatcodes like P, P0, P1, etc.?
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"Matt Swift" <MattSwift@.discussions.microsoft.com> wrote in message
news:EA1C086B-CA02-4314-8CED-970B2D72B5EB@.microsoft.com...
> My query returns numbers to the report, these are already rounded (this is
> made to happen in query as they are cast to int).
> After I get these integers to my report, I tend to group them, and AVG a
> group set. If there is a lot of the numbers in the equation, the total
> tends
> to decimalise to a really ridiculous number (x.xxxxxxxxxxxx). So, I try
> putting d or n in the custom format properties for this textbox, I also
> try a
> number of the default formatting options. Even I try to use the <format>
> tag
> in the XML. All to no effect.
> The only thing I can think is that I tend to write out a '%' after the
> number (to show it's a percentage, it's purely cosmetic). Here is a line
> of
> the AVG function, and how I am using it . I would really appreciate it if
> anyone knew what I might be goofing up on here!
> =iif(Avg(Fields!DoneIt.Value) = 0, "0%", Avg(Fields!DoneIt.Value) & "%")|||In your report, go to [ Report Properties ] from your [ Report ] menu.
On the [ Code ] tab, paste this in...
--[ BEGIN CODE ]--
Public Function ConvertToInt(ByVal x_obj As Object) As String
Return String.Format("{0:#}", x_obj)
End Function
--[ END CODE ]--
Now, change your textbox's formula to:
=ConvertToInt(Avg(Fields!DoneIt.Value)) & "%"
Andrew Bruderer
"Robert Bruckner [MSFT]" wrote:
> Did you try just using the following expression:
> =Avg(Fields!DoneIt.Value)
> and then just use formatcodes like P, P0, P1, etc.?
>
> -- Robert
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "Matt Swift" <MattSwift@.discussions.microsoft.com> wrote in message
> news:EA1C086B-CA02-4314-8CED-970B2D72B5EB@.microsoft.com...
> > My query returns numbers to the report, these are already rounded (this is
> > made to happen in query as they are cast to int).
> >
> > After I get these integers to my report, I tend to group them, and AVG a
> > group set. If there is a lot of the numbers in the equation, the total
> > tends
> > to decimalise to a really ridiculous number (x.xxxxxxxxxxxx). So, I try
> > putting d or n in the custom format properties for this textbox, I also
> > try a
> > number of the default formatting options. Even I try to use the <format>
> > tag
> > in the XML. All to no effect.
> >
> > The only thing I can think is that I tend to write out a '%' after the
> > number (to show it's a percentage, it's purely cosmetic). Here is a line
> > of
> > the AVG function, and how I am using it . I would really appreciate it if
> > anyone knew what I might be goofing up on here!
> >
> > =iif(Avg(Fields!DoneIt.Value) = 0, "0%", Avg(Fields!DoneIt.Value) & "%")
>
>