Decimal Round figure Condition - sql

enter image description hereI want to round the figure of "Rate" if the decimal value becomes .5 or higher (For Example if 17.57 I want it as 18, if 20.98 I want it as 21)
On the other hand, if the decimal value becomes lower than .5 (For Example if 17.23 I want it as 17, if 20.49 I want it as 20)
I am attaching an image. Please let me know the condition.Thank you.

You just need use Round() function as below:
select round(86.54,0) //zero will fix in your case

Use round function
select round('19.6',0)
Result

Related

Handling Nulls while calculating percentiles in Hive

Am having some troubles in handling nulls while calculating percentiles. Below is the sample data.
enter image description here
Code that am using now: percentile(column_1, array(0, 0.25, 0.50, 0.75, 1)) as column_1_p
Here it considers null values too while calculating percentiles. But I need to eliminate them and only use other valid values to calculate percentiles. I couldn't find any other function which does this.
Data: Values range from zero to 1000. I cannot replace nulls with zeros, as I already have zeros in data.
Any help here is highly appreciated.
Thanks in advance.

SQL | How to always round up regardless of the last integer value, even when that may be 0

I am currently outputting values out to 6 decimal places, and would like to round up the 6th place regardless of the integer value.
I have been using a CEILING() function so far which has worked great for values 1-9 on rounding up; however, in situations where I have the 7th decimal as 0 (ex: 2705.1520270), the function does not round up to 2705.152028.
select CEILING(price*1000000)/1000000 as PriceRound
from tc_alcf a (nolock)
Here is one approach:
SELECT ROUND(2705.1520270 + 0.0000005, 6);
2705.1520280
Demo
We can add 0.0000005 to the input and then just use SQL Server's ROUND function to 6 decimal places. This works because values with a sixth decimal place between 0 and 0.4999 (repeating) would become 5 to 0.9999 (repeating), meaning they would round up to the next digit. And values with already have 5 or greater in the sixth decimal place would not be bumped up to the next digit.
This problem should be familiar to many developers as the rounding half up problem.
Add 1 and use FLOOR():
select floor(price*1000000 + 1)/1000000 as PriceRound
from tc_alcf a
Or you can also shift the decimal by multiplying with the power function
CEILING(2705.1520275 * POWER(10,6)) / POWER(10,6)

How to use the displayed value on powerbuilder for computation

I just want to ask on how to solve my problem.
On my report window, 2 computed fields:
1. A field that computes for decimal and I am displaying it to two decimals only (no problem on the display).
2. On my other computed field, I use the result of the first computed field to be multiplied to a certain number. The problem is here, because the value being multiplied is not the value being displayed from the first field. Instead it uses the whole amount.
Scenario:
2,055,232.135 is the computed value and id displays 2,055,232.14 which is good.
But if i multiply it to 9 (2055232.135 * 9), the result is 18,497,089.215 which will be displayed as 18,497,089.22
The problem is I want that the displayed value (2,055,232.14) to be multiplied to 9 (2055232.14 * 9) which will then results to 18,497,089.26
I only wanted to achieve the 2nd value for the computed field so that if the user computes for it, it will be equal.
The following solution can be used in a computed field:
String( Truncate( 2055232.135 * 9, 2), "#,##0.00")

rdlc (piechart) customized colors for different segments

I have written a code like below, my problem was sometimes I am getting same color for different segments in the piechart if the value came from the same range.
ref:
rdlc expression iif use?
my code sample
=SWITCH(Fields!ID__Share_of_Costs.Value <= 0.99, "Yellow",
Fields!ID__Share_of_Costs.Value <= 30, "Teal",
Fields!ID__Share_of_Costs.Value <= 60, "SteelBlue",
Fields!ID__Share_of_Costs.Value <= 100, "Crimson",
)
for eg: suppose my chart value is dynamic and it will come like 22 and 29, in this case the segment will show the same color (<= 30, "Teal",) as it is difficult to differntiate. Is there is any way to give different colors for each segment like no repeated color ?
Thanks in advance...cheers
It depends what do you mean by segment (range of values or particular value) or in other words is number of your segments limited?
If yes, then you could set up as much segments as you want with particular color.
If no, then write a custom function which will return hex value as your color.

vb.net what is a good way of displaying a decimal with a given maximum length

I am writing a custom totaling method for a grid view. I am totaling fairly large numbers so I'd like to use a decimal to get the total. The problem is I need to control the maximum length of the total number. To solve this problem I started using float but it doesn't seem to support large enough numbers, I get this in the totals column(1.551538E+07). So is there some formating string I can use in .ToString() to guarentee that I never get more then X characters in the total field? Keep in mind I'm totaling integers and decimals.
If you're fine with all numbers displaying in scientific notation, you could go with "E[numberOfDecimalPlaces]" as your format string.
For example, if you want to cap your strings at, say, 12 characters, then, accounting for the one character for the decimal point and five characters needed to display the exponential part, you could do:
Function FormatDecimal(ByVal value As Decimal) As String
If value >= 0D Then
Return value.ToString("E5")
Else
' negative sign eats up another character '
Return value.ToString("E4")
End If
End Function
Here's a simple demo of this function:
Dim d(5) As Decimal
d(0) = 1.203D
d(1) = 0D
d(2) = 1231234789.432412341239873D
d(3) = 33.3218403820498320498320498234D
d(4) = -0.314453908342094D
d(5) = 000032131231285432940D
For Each value As Decimal in d
Console.WriteLine(FormatDecimal(value))
Next
Output:
1.20300E+000
0.00000E+000
1.23123E+009
3.33218E+001
-3.1445E-001
3.21312E+016
You could use Decimal.Round, but I don't understand the exact question, it sounds like you're saying that if the total adds up to 12345.67, you might only want to show 4 digits and would then show 2345 or do you just mean that you want to remove the decimals?