how can I fix my method of converting Bytes To Megabytes not to get as a Result NaN. This is my method:
Public Function BytesToMegabytes(bytes As Long) As String
Dim dblAns As Double = (bytes / 1024) / 1024
If dblAns = 0 Then
Return "0"
End If
Dim significantFigures = 4
Dim magnitude = Math.Floor(Math.Log10(dblAns)) 'In this Line I get the NaN
Dim v As Double = 10 ^ (magnitude - significantFigures + 1)
dblAns = Math.Floor(dblAns / v) * v
Dim ci = New CultureInfo("")
ci.NumberFormat.NumberDecimalSeparator = ","
ci.NumberFormat.NumberGroupSeparator = "'"
Return dblAns.ToString("#,##0.###", ci)
End Function
With Dim usedInklData = BytesToMegabytes(-3271356861)
I get the correct result.
and with Dim usedInklData = BytesToMegabytes(-776150324)
I get the NaN value.
Please suggest how I could correct this.
Thanks to everyone for their help.