Changeset 2811 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Apr 8, 2020, 10:30:47 PM (5 years ago)
Author:
lfita
Message:

Rounding truncation to the latest decimal

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r2810 r2811  
    1411214112    fname = 'truncate'
    1411314113
    14114     multiplier = 10. ** decimals
     14114    dec = decimals + 1
     14115    multiplier = 10. ** dec
    1411514116    tfv = int(fv * multiplier) / multiplier
    1411614117
    14117     return int(fv * multiplier) / multiplier
     14118    # decimals section
     14119    decsec = int(fv*multiplier-int(fv)*multiplier)
     14120   
     14121    # last decimal
     14122    if decsec != 0.:
     14123        lastdecsec = int((decsec/10. - int(decsec/10.))*10)
     14124        if lastdecsec > 5.:
     14125            decsec = decsec + 1
     14126            fv = int(fv) + decsec/multiplier
     14127
     14128    dec = decimals
     14129    multiplier = 10. ** dec
     14130    tfv = int(fv * multiplier) / multiplier
     14131
     14132    return tfv
    1411814133
    1411914134def angle_DegMinSec(angle):
     
    1412914144   degv = int(abs(angle))
    1413014145   minv = int((abs(angle) - degv*1.)*60.)
    14131    secv = (abs(angle) - degv*1. - minv/60.)*3600.
    14132 
     14146   secv = truncate((abs(angle) - degv*1. - minv/60.)*3600., 7)
    1413314147   if secv < 1.e-8: secv = 0.
    1413414148                                                 
Note: See TracChangeset for help on using the changeset viewer.