Solved

# Problem(s) with Math.Round

Posted on 2012-08-22
485 Views
I have this function and i want to return the Rounded (to nearest 1MB) of it...

``````private static string EstimatedFileSize(double videoBtr_Mbits, uint audioBtr_Kbits, uint video_length_sec)
{
// Video Bitrate = [Video Bitrate (Kilobits/Sec) + Audio Bitrate (Kilobits/Sec)]
var videoBtr_Sum = (uint)((videoBtr_Mbits * 1024) + audioBtr_Kbits);

// File size = Video Bitrate (Kilobits) * Video Length (Seconds) => kbytes
var fSize_kbyte = ((videoBtr_Sum * video_length_sec) / 8) * 1024;

return CommonUtility.FileSizeToString(fSize_kbyte.ToString());
}
``````
0
Question by:rotem156
1 Comment

LVL 16

Accepted Solution

So what is that problem?

The one thing that looks questionable is the fact that var videoBtr_Sum is apparently already in Kbits (because you multiply a value that seems to be in Mbits by 1024 to make it Kbits), then when calculating var fSize_kbyte, you multply by 1024 again (and I don't know what the /8 is for).

Perhaps var fSize_kbyte should really be fSize_byte (then the * 1024 would make sense).

To get fSize_byte rounded to the nearest 1MB, simply add 1/2 M and divide by 1M...
fSize_MByte = (uint)(( fSize_byte + 512 * 1024 ) / ( 1024 * 1024 ))
0

## Featured Post

### Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…