Confirm Calculation for Data Transfer - data-transfer

I would like to confirm my calculation for data transfer:
Assume, I have 1 PB of data and a network bandwidth of 1 Gbps, how long will it take to transfer the data.
I have the following calculation:
1 PB = 1,000,000 GB (decimal)
Therefore, it will take 1,000,000 / (60 * 60 * 24) = 11.57 days to transfer the data.
Is this correct?

I think it will be (1,000,000 * 8) / (60 * 60 * 24) = (11.57 * 8) .
Since 1B = 8 bit

Related

Calculation of countdown timer

How numerators and denominators of days, hours and minutes are calculated in this code, why modulus is calculated in numerator?
var countDownDate = new Date("Sep 5, 2018 15:37:25").getTime();
var x = setInterval(function() {
var now = new Date().getTime();
var distance = countDownDate - now;
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
document.getElementById("demo").innerHTML = days + "d " + hours + "h " + minutes + "m " + seconds + "s ";
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
Let me explain it line by line:
var countDownDate = new Date("Sep 5, 2018 15:37:25").getTime();
In the above line, you are getting the milliseconds for the date Sep 5, 2018 15:37:25 from Jan 1, 1970 (which is the reference date being used by getTime()
var now = new Date().getTime();
var distance = countDownDate - now;
The above two lines are simple. now gets the current time in milliseconds and distance is the difference between the two times (also in milliseconds)
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
The total number of seconds in a day is 60 * 60 * 24 and if we want to get the milliseconds, we need to multiply it by 1000 so the number 1000 * 60 * 60 * 24 is the total number of milliseconds in a day. Dividing the difference (distance) by this number and discarding the values after the decimal, we get the number of days.
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
The above line is a little tricker as there are two operations. The first operation (%) is used to basically discard the part of the difference representing days (% returns the remainder of the division so the days portion of the difference is taken out.
In the next step (division), 1000 * 60 * 60 is the total number of milliseconds in an hour. So dividing the remainder of the difference by this number will give us the number of hours (and like before we discard the numbers after decimal)
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
This is similar to how hours are calculated. The first operation (%) takes out the hours portion from difference and the division (1000*60) returns the minutes (as 1000 * 60 is the number of milliseconds in a minute)
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
Here the first operation (%) takes out the minutes part and the second operation (division) returns the number of seconds.
Note: You might have noticed that in every operation the original distance is used but the code still works fine. Let me give you an example (I am using difference instead of distance as this name makes more sense).
difference = 93234543
days = Math.floor(89234543 / (1000 * 60 * 60 * 24))
=> days = 1
hours = Math.floor((89234543 % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
(result of modulus operation is 6834543, and division is )
=> hours = 1
This is a very important operation to understand:
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
distance(difference) / (1000 * 60 * 60) returns 25 (hours). As you can see we have already got 1 day and 1 hour (25 hours) so distance % (1000 * 60 * 60) wipes out all of these 25 hours and then the division calculates the minutes and so on.

Converting rate charge formula to C expression

A call is charged 30 cents per minute.
The cost for line rental is RM60.00. The tax for the overall bill including the line rental) is 15%.
Calculate the amount, that needs to be paid by the user given the number of
minutes that the user uses his/her mobile phone.
How can I transform this formula into C code?
rate = (minute*0.30)+15/100 *60
The formula is wrong. You first need to multiply the number of minutes by 30 cents, then add the 60 for the rental, and only then apply the tax by multiplying by 1.15:
int minutes = // inputted from user...
double total = ((0.3 * minutes) + 60) * 1.15;
I think is just that:
float minute;
float rate;
printf("How many minutes?");
scanf("%f", &minute);
rate = (minute * 0.3 + 60) + 0.15 * (minute * 0.3 + 60);

Round 916.984800 to 916.99

Is it possible to round 916.984800 to 916.99 in SQL Server?
I've tried as below but I don't want '+ 0.1' as my solution.
Round((((424.53 - 0) * 36) * (6 / 100)),2) + .01 as [Amount]
or
Round((((424.53 - 0) * 36) * (0.06)),2) + .01 as [Amount]
Thanks
This produces expected output:
SELECT CEILING((424.53 - 0) * 36 * 0.06 * 100) / 100 AS [Amount]
Amount
----------
916.990000
What happens?
SELECT (424.53 - 0) * 36 * 0.06 * 100
This returns 91698.4800, CEILING returns the smallest integer greater than, or equal to, the specified numeric expression, in your case 91699, and later I just divide it by 100, which brings expected result.

Database calculations are wrong

Here is what I'm setting:
result = price / (case when tax = 0 then #tax1h / 100 else #tax2 / 100 end + 1)
These are the values:
price = 17.5
tax = 1
tax2 = 6
17.5 / (6 / 100 + 1) = 16.5
And this returns 17.5 Why is this happening and how to solve it?
Integer division:
select (6 / 100 + 1)
The result of the above is 1.
However, the result of:
select (6 / 100.0 + 1)
Is 1.06.

What does "linear interpolation" mean?

I often hear the term "linear interpolation" in context with animations in WPF. What exactly does "linear interpolation" mean? Could you give me an example where to use "linear interpolation"?
Linear means lines (straight ones).
Interpolation is the act of finding a point within two other points. Contrast this with extrapolation, which is finding a point beyond the ends of a line.
So linear interpolation is the use of a straight line to find a point between two others.
For example:
*(5,10)
/
/
/
/
*(0,0)
You can use the two endpoints with linear interpolation to get the points along the line:
(1,2)
(2,4)
(3,6)
(4,8)
and linear extrapolation to get (for example):
(1000,2000)
(-1e27,-2e27)
In animation, let's say you have a bouncing ball that travels from the (x,y) position of (60,22) to (198,12) in 10 seconds.
With an animation rate of 10 frames per second, you can calculate it's position at any time with:
x0 = 60, y0 = 22
x1 = 198, y1 = 12
frames = 100
for t = 0 to frames:
x = (x1 - x0) * (t / frames) + x0
y = (y1 - y0) * (t / frames) + y0
Those two formulae at the bottom are examples of linear interpolation. At 50% (where t == 50):
x = (198 - 60) * (50 / 100) + 60
= 138 * 0.5 + 60
= 69 + 60
= 129
y = (12 - 22) * (50 / 100) + 22
= -10 * 0.5 + 22
= -5 + 22
= 17
and (129,17) is the midpoint between the starting and ending positions.
E.g. when you want a storyboard to move an element from one position to another using a fixed speed, then you'd use linear interpolation between the start and end positions.

Resources