Home > Community > Forums > Custom IC Design > Changing floating number precision in SKILL

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 Changing floating number precision in SKILL 

Last post Tue, Oct 27 2009 8:04 AM by sprinter. 4 replies.
Started by sprinter 26 Oct 2009 02:17 PM. Topic has 4 replies and 1785 views
Page 1 of 1 (5 items)
Sort Posts:
  • Mon, Oct 26 2009 2:17 PM

    • sprinter
    • Top 500 Contributor
    • Joined on Tue, Sep 29 2009
    • Posts 17
    • Points 310
    Changing floating number precision in SKILL Reply

    How can I change the precision of a floating number. For example I'm trying to convert 23.3455 to 23.34 & this's what I'm doing:

     x=23.3255

    y=printf("%5.2f" x)

    'y' is now a symbol. HOw can this be converted to a floating number?

     

    Thanks,

    Adil

    • Post Points: 35
  • Mon, Oct 26 2009 5:33 PM

    • kbhow
    • Top 75 Contributor
    • Joined on Thu, May 7 2009
    • Penang, Pulau Pinang
    • Posts 120
    • Points 2,045
    Re: Changing floating number precision in SKILL Reply

    Hi Adil,

    In order to get the value of a string, you can use function evalstring.

    Eg: x = 23.3255

          sprintf(y "%5.2f" x)  ; this will return y="23.33"

          evalstring(y) ; evaluate string value, you will get your answer here

     Happy testing

    How

    • Post Points: 5
  • Mon, Oct 26 2009 5:55 PM

    • Quek
    • Top 10 Contributor
    • Joined on Wed, Oct 14 2009
    • Singapore, 00-SG
    • Posts 1,084
    • Points 16,515
    Re: Changing floating number precision in SKILL Reply

    Hi Adil

    How about this? : )

    y=evalstring(sprintf(nil "%5.2f" x))

    Best regards
    Quek

    • Post Points: 20
  • Mon, Oct 26 2009 9:26 PM

    Re: Changing floating number precision in SKILL Reply
    Personally I never like using evalstring for things like this.

    I'd probably do:

    y=round(x*100)/100.0

    If you really want to use the sprintf approach, you could use atof() instead of evalstring.

    Regards,

    Andrew
    • Post Points: 20
  • Tue, Oct 27 2009 8:04 AM

    • sprinter
    • Top 500 Contributor
    • Joined on Tue, Sep 29 2009
    • Posts 17
    • Points 310
    Re: Changing floating number precision in SKILL Reply

    Thanks everybody!

    Regards,

    Adil.

    • Post Points: 5
Page 1 of 1 (5 items)
Sort Posts:
Started by sprinter at 26 Oct 2009 02:17 PM. Topic has 4 replies.