1

Nastran GRID format

I have a problem to read the some negative exponent values from NASTRAN.bdf file. For example, this list contains z co-ordinates.

How to convert -5.75-3 into -5.75e-3 ?

  • Could you embed some code snippet here of what you already tried? – MWiesner Dec 13 '15 at 12:48
  • @MWiesner: tried to seperate -5.75 and -3 then inserted e. I want float value to be 8 digit wide and Right aligned.Which is not always true for below code. _italic_ and **bold** text, inline ` x= -2.3-3"` `print x` `if x[6]=='-':` ` lenx=len(x)` ` print lenx` ` if lenx<7:` ` x=x[2:6]+'E'+x[6:8]` ` x='{0:>8}'.format(x)` ` else:` ` x=x[:5]+'E'+x[6:8]` ` x='{0:>8}'.format(x)` `print x ` – Chetan Patil Dec 15 '15 at 05:04

1 Answers1

0

I had the same problem today and wrote something like this:

def nastran_float(s):
    s = s.replace('-','e-')
    s = s.replace('+','e+')
    if s[0] == 'e':
        s = s[1:]
    return float(s)
Andrew
  • 1
  • 1