Round decimals in report formula - crystal-reports

My Crystal Report needs to round numbers to two decimal points. I have tried Round(55.815, 2) but it returns 55.81 instead of 55.82. How can I resolve this?

If you need to round the decimal for display purposes, simply use the "Decrease Decimals" icon:

just try this
if Remainder(55.815 ,1) > 0.5 then
Floor (55.815) + Remainder(55.815 ,1)
else
Floor (55.815 )+ Remainder(55.815 ,1)
This may be help you

Related

Numeric (not integer or double precision) picture token Clarion+Postgresql

i need numeric mask like this:
100
101.1
102.123
Take maksimum given decimal places but if last digit is 0 trim it.
Something like:
#n-12_`2 but trim right 0 and .
Ex:
x = 102.1230057::double precision
select rtrim(rtrim(round(x::numeric, 2)::text, '0'), '.')::numeric
If you don't need right aligned numbers, you can use #S10 (or the length you want).
#P<#.##P style pictures might help.

Crystal reports formula using variables

I need a formula like this:
if {#TarSale_TimeWise}= 0 or isnull({#TarSale_TimeWise}) then '-'
else
totext(round(({#ActSale_TimeWise}-{#TarSale_TimeWise})/{#TarSale_TimeWise}*100,1),1)
Here the formula for {#TarSale_TimeWise} is
round({CatTimeWise.tarSale},1)
Similarly the formula for {#ActSale_TimeWise} is
round({CatTimeWise.ActSale},1)
I need to take rounding as 1 for both the fields and then I need to do the calculation for var sale with values round as 1 for both the formulas.
Now instead of creating this below 2 formulas and using those in 3rd formula I want to create only one formula using variables.
How can I modify above formulas as 1 formula?
Create only one formula and write below code:
Local Numbervar a1:=round({CatTimeWise.tarSale},1) ;
Local NumberVar a2:=round({CatTimeWise.ActSale},1) ;
if a1= 0 or isnull(a1) then '-'
else
totext(round((a2-a1)/a1*100,1),1)
Try:
If Isnull({CatTimeWise.tarSale}) Or {CatTimeWise.tarSale}=0 Then
'-'
Else
ToText( Round( (({CatTimeWise.ActSale} - {CatTimeWise.tarSale}) / {CatTimeWise.tarSale}*100), 1), 1 )

TSQL Round() inconsistency?

The problem we have is reduced to the following two statements:
select convert(float, (convert(float,5741.61)/convert(float, 196.00)) * convert(float,14.00)) as unrounded, round(convert(float, (convert(float,5741.61)/convert(float, 196.00)) * convert(float,14.00)), 2) as roundedTo2dp
select convert(float, 410.115) as unrounded, ROUND( convert(float, 410.115), 2) as roundedTo2dp
The first statement uses floats to calculate a value of 410.115, and also that result with a round() to 2 decimal places. The rounded value comes out at 410.11.
The second statement uses the float value 410.115 and also rounds it to 2 decimal places. The rounded result comes out as 410.12.
Why is one rounding down and the other rounding up when the value being rounded it the same?
How can I get the first statement to round to 410.12?
EDIT: apologies for formatting -- stackoverflow isn't showing any formatting on this machine (very odd).
Decimals are better with precision than floats. If you changed up the float to be something like DECIMAL(18,2), you'll get what you are expecting and you don't need to call the round function anymore.
select convert(decimal(18,2), (convert(decimal(18,2),5741.61)/convert(decimal(18,2), 196.00)) * convert(decimal(18,2),14.00)) as unrounded, round(convert(decimal(18,2), (convert(decimal(18,2),5741.61)/convert(decimal(18,2), 196.00)) * convert(decimal(18,2),14.00)), 2) as roundedTo2dp
results in
unrounded roundedTo2dp
410.12 410.12
Link to the MSDN about decimals. http://msdn.microsoft.com/en-us/library/ms187746.aspx
Hope that helps...
The numbers are not equal:
SELECT CAST(convert(float, (convert(float,5741.61)/convert(float, 196.00)) * convert(float,14.00)) AS BINARY(8))
UNION ALL
SELECT CAST(convert(float, 410.115) AS BINARY(8)) as bin
----
0x4079A1D70A3D70A3
0x4079A1D70A3D70A4
'float' is an approximate number data type and hence not all values in the data type range can be represented exactly.
This is based on http://msdn.microsoft.com/en-us/library/ms173773.aspx.
I believe this is why there is rounding issue while using float values. You can never be 100% sure!
Ex.
Select round(convert(float, 1.5555), 2) --Gives 1.56
Select round(convert(float, 1.555), 2) --Gives 1.55!
With such a simple number there is difference in expected result while using float.

convert function from Access SQL to T-SQL 2005

Can someone please convert this access sql function for me to work in t-sql 2005.
I am tring to take the selling price minus the cost as one number. And divide that by the original selling price to produce a second number
Thanks :)
=IIf([Selling Price]=0,0,([Selling Price]-Nz([Cost]))/[Selling Price])
IIRC it should be something along the lines of;
ISNULL((ISNULL([Selling Price],0) - ISNULL(Cost,0)),0) / ISNULL([Selling Price],0) AS Margin
But here I am getting a divide by Zero error.
any suggestions?
SELECT
CASE
WHEN ISNULL([Selling Price],0) = 0 THEN 0
ELSE ([Selling Price] - ISNULL([Cost],0))/[Selling Price]
END AS fieldName
FROM TableName
CASE
WHEN ISNULL([Selling Price], 0) = 0 THEN 0
ELSE ([Selling Price] - ISNULL([Cost], 0)) / [Selling Price]
END

how do I round numbers with NSNumberFormatter

I've got a calculation for example 57 / 30 so the solution will be 1,766666667..
How do i first of all get the 1,766666667 i only get 1 or 1.00 and then how do i round the solution (to be 2)?
thanks a lot!
57/30 performs integer division. To obtain a float (or double) result you should make 1 of the operands a floating point value:
result = 57.0/30;
To round result have a look at standard floor and ceil functions.