有没有更好的方法来获得vb.net上5个最有效的数字?

时间:2017-11-04 09:20:01

标签: vb.net

在vb.net上获得5位最有效数字的更好方法是什么?

         436523423900000->43652 
         .0000000034543853658400003763746 -> 34543 

这是我目前的代码: -

Public Function priceSignficant() As Double
    Dim lnPrice = Math.Log10(_price)
    Dim floorLnPrice = Math.Floor( lnPrice )
    Dim significantprice = 10 ^ floorLnPrice


    Return significantprice
End Function
Public Function priceSignificantDigit() As ULong
    Dim pricesig = priceSignficant()
    Dim ratio = _price / pricesig
    Dim i = 0
    Do
        Dim closeenough = ratio - Math.Round(ratio)
        Dim closeneough1 = Math.Abs(closeenough)
        If closeneough1 > 0.000000001 Then
            ratio *= 10
            i += 1
            If i > 5 Then
                Exit Do
            End If
        Else
            Exit Do
        End If
    Loop

    Return CULng(ratio)
End Function

这是一种工作。

必须有更简单的方法。

1 个答案:

答案 0 :(得分:2)

对于正数,您可以使用import pandas as pd df = pd.read_csv('filename.csv', header=None) df.columns = ['id', 'name', 'number', 'time', 'text_id', 'text', 'text'] print(df) for eachname in df.name.unique(): eachname_df = df.loc[df['name'] == eachname] grouped_df = eachname_df.groupby(['id', 'name']) avg_name = grouped_df['time'].mean() for a, b in grouped_df: if b['time'].mean() != avg_name.min(): indextodrop = b.index.get_values() for eachindex in indextodrop: df = df.drop([eachindex]) print(df) Result: id name number time text_id text text 0 1 apple 12 123 2 abc abc 1 1 apple 12 222 2 abc abc 2 2 orange 32 123 2 abc abc 3 2 orange 11 123 2 abc abc 4 3 apple 12 333 2 abc abc 5 3 apple 12 443 2 abc abc 6 3 apple 12 553 2 abc abc id name number time text_id text text 0 1 apple 12 123 2 abc abc 1 1 apple 12 222 2 abc abc 2 2 orange 32 123 2 abc abc 3 2 orange 11 123 2 abc abc 计算位数,然后使用除法将数字移动此数量(减去5):

Log10

如果您有负数,请使用Dim numberOfDigits = Math.Ceiling(Math.Log10(number)) Dim significantDigits = Math.Truncate(number * Math.Pow(10, 5 - numberOfDigits)) 计算绝对值,并按上述步骤继续。