How to round up the value end with Zero in asp.net mvc5 - asp.net-mvc-5

Hi i need to round up the value end with Zero (end value to be 0, like 450, 55000, 4560). i want to round up the value with ending zero eg if i got value like 102498 means round up value like 102500 and if i got value like 47504 means round up value like 47500 this i have to do in mvc eg values 999 =>1000 994=>990 995=>990 i have to do this roundup in table view page.

I'd suggest starting with:
Decimal value = 102498;
var rounded = Math.Round(value / 10, MidpointRounding.AwayFromZero) * 10;
Console.WriteLine(rounded);
The steps are:
Divide by 10
Round (.5 up, below .5 down - AwayFromZero)
Multiply by 10 (this ensures the last digit is always 0)

Related

Excel Random number from a set of options

In MS Excel, how can I randomly sum up to a target number with numbers divisible by 5?
For example, I would like a completely random output of numbers divisible by 5 (5,10,15,20….) in cells B1:B100, to add up to 10000.
I initially looked at the CHOOSE(RANDBETWEEN) option but I can't get up to make the numbers add up to 10000.
In Office 365, B1 enter the formula:
=LET(
rndArr,RANDARRAY(100,1),
Correction,INT(SEQUENCE(100,1,1,-1/100)),
INT(rndArr/SUM(rndArr)*2000)*5+IF(Correction=1,10000-SUM(INT(rndArr/SUM(rndArr)*2000)*5),0))
EDIT: the below added in response to the comment about constraining it to a min/max. It's not actually foolproof for all min/max values, but seemed to work well enough for me with the values you supplied.
=LET(
Total, 10000,
Min, 10, Max, 300,
rndArr, RANDARRAY(100, 1),
Correction, SEQUENCE(100, 1, 1, 1) = MATCH(MIN(rndArr), rndArr, 0),
rndArr5, INT(rndArr/SUM(rndArr)*Total/5)*5,
rndArrMinMax, IFS(rndArr5 < Min, Min, rndArr5 > Max, Max, TRUE, rndArr5),
rndArrMinMax + (Total-SUM(rndArrMinMax)) * Correction
)
Explanation of what that does:
Enter Total, Min and Max variables
create rndArr, an array of random numbers (that is the correct size, 100 rows x 1 col)
create Correction, a boolean array of the same size as rndArr where the only TRUE value is the position of the smallest value in rndArr. This is because we'll need to add a figure in later to ensure the total is correct, and want to add it to the smallest number in the array (best possible chance that it won't go above our maximum, remember I said this wasn't foolproof for all values).
create rndArr5, which proportionately increases rndArr so it totals 2000, rounds down to nearest integers, then multiplies by 5. The result is an array of random multiples of 5 that totals somewhere below 10000
create rndArrMinMax by checking rndArr5 (our progress so far) against desired min and max values, editing any outside of our desired range to be the min or max value respectively.
Final output value is that corrected value, plus any difference to make the correct total (that's Total - SUM(rndArrMinMax), which is multiplied by our Correction boolean array so it only gets added on the smallest value in the array. Again, this may result in that smallest value going over the max if the totals are way out and/or the Max is very small, but there's not much you can do about that with random numbers.

Round time to nearest 10 milliseconds

I have some time data that, without VBA, I need to round to the nearest 10 milliseconds. For example:
input: 01:02:03.017 output: 01:02:03.020
input: 03:12:44.123 output: 03:12:44.120
Current approach is to convert to an integer number of milliseconds; round that to the nearest 10; finally convert back to time:
=ROUND(A1*86400000,10)/86400000
I must be making a really stupid error, just don't see it.
EDIT:
The formula is returning the same value as the input?!?
Change the 10 to 0
By multiplying the value you want the round to the nearest integer, then divide again. By using 10 you are rounding to the 10th decimal place after creating a integer time.
=ROUND(A1*86400000,0)/86400000
Assuming your time data is in column A:
=TEXT(A1,"hh:mm:ss.00")+0
Change the number format with TEXT, then add the ending 0 with +0

Rounding number in SSRS2008-R2 Reports

I have a report in RS.
One of the cells in my tablix have the following expression:
=Round((Fields!Volume.Value * 100) / First(Fields!Volume.Value,"RankingProduct"),2)
As you cann see, Im doing a Rule of three so the total is my first row of the Volume field.
Now, all the elements must sum 100%, but it does only if I take the Round function out.
The customer wants to see 2 decimals but at the same time wants all the elements to sum 100%. I understand both are mutually exclusive.
Example:
Value with all decimals: 0,005100972740331660000000000000
Value with the 1st two decimals rounded: 0,010000000000000000000000000000
So if you have one or two thousand of these will never reach 100% as I lose the precision.
So the only solution would be to leave all the decimals?
You can operate the simple calcul without rounding in the expression
=Round((Fields!Volume.Value * 100) / First(Fields!Volume.Value,"RankingProduct"),2)
become
=(Fields!Volume.Value * 100) / First(Fields!Volume.Value,"RankingProduct")
Then, you right click on the text box, choose Text box property -> Number, and you can select the 2 decimal display.

how to convert this excel formula in english words?

can someone please translate this excel spreadsheet cell formula in english words ?
=ROUND(IF(F28 < 1568,2.5,IF(F28 < 2491,0.004873 * F28-5.142,0.02269*F28^0.7329)),2)
am creating a program based from that formula, but i don't understand which one will go first. atleast i understand this part IF(F28 is less than 1568) ...then what?
Start from the outer if statement and move inwards. The comma in the IF function separates the statements like :
boolean expression, true part, and false part
The following is the psuedo code of the above. All the Round are to two decimal places.
IF (F28 < 1568) THEN
ROUND (2.5)
ELSE IF (F28 < 2491) THEN
ROUND (0.004873 * F28 - 5.142)
ELSE
ROUND (0.02269 * F28^0.7329)
If the value in cell F28 is less than 1568, then the value in this cell will be 2.5 rounded to 2 decimal places - i.e. 2.5
If the value in cell F28 is 1568 or more, but less than 2491, then the value in this cell will be:
0.004873 multiplied by [the value in cell F28 minus 5.142], rounded to 2 decimal places
Otherwise (i.e. the value in cell F28 is 2491 or more) the value in this cell will be: 0.02269 multiplied by [the value in cell F28 to the power of 0.7329], rounded to 2 decimal places
You will round the following in this order:
Smaller than 1568 = 2.5
Bigger than/Equal 1568 but smaller than 2491 = 0.004873 * F28-5.142
Bigger than/Equal 2491 = 0.02269*F28^0.7329
Basically that means this:
IF F28 is smaller than 1568 then use 2.5
IF F28 is larger or equal to 1568 but smaller than 2491 then use 0.0004873 * F28 - 5.142
IF F28 is larger or equal to 2491 then use 0.02269 * F28^0.7329
Round the outcome to 2 digits.

How to roundup a number to the closest ten?

Probably the title is not very suggestive.
Let me explain you with an example. I have:
12345.6
2345.1
12345.00000001
I want those numbers to be roundup to 12350.
How can I do this?
If possible, I would rather use formulas instead of VBA.
You could also use CEILING which rounds up to an integer or desired multiple of significance
ie
=CEILING(A1,10)
rounds up to a multiple of 10
12340.0001 will become 12350
Use ROUND but with num_digits = -1
=ROUND(A1,-1)
Also applies to ROUNDUP and ROUNDDOWN
From Excel help:
If num_digits is greater than 0 (zero), then number is rounded to the specified number of decimal places.
If num_digits is 0, then number is rounded to the nearest integer.
If num_digits is less than 0, then number is rounded to the left of the decimal point.
EDIT:
To get the numbers to always round up use =ROUNDUP(A1,-1)
You can use the function MROUND(<reference cell>, <round to multiple of digit needed>).
Example:
For a value A1 = 21 round to multiple of 10 it would be written as
=MROUND(A1,10)
for which Result = 20
For a value Z4 = 55.1 round to multiple of 10 it would be written as
=MROUND(Z4,10)
for which Result = 60
the second argument in ROUNDUP, eg =ROUNDUP(12345.6789,3) refers to the negative of the base-10 column with that power of 10, that you want rounded up. eg 1000 = 10^3, so to round up to the next highest 1000, use ,-3)
=ROUNDUP(12345.6789,-4) = 20,000
=ROUNDUP(12345.6789,-3) = 13,000
=ROUNDUP(12345.6789,-2) = 12,400
=ROUNDUP(12345.6789,-1) = 12,350
=ROUNDUP(12345.6789,0) = 12,346
=ROUNDUP(12345.6789,1) = 12,345.7
=ROUNDUP(12345.6789,2) = 12,345.68
=ROUNDUP(12345.6789,3) = 12,345.679
So, to answer your question:
if your value is in A1, use
=ROUNDUP(A1,-1)

Resources