• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. Test if string is Number

Stats

  • Locked Locked
  • Replies 10
  • Subscribers 144
  • Views 9655
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Test if string is Number

FranzD
FranzD over 2 years ago

Hi,

I want to check if a string is a number or not. For example if I have  string1 = "10u" I want to use it to callculated some stuff but if string1 = "MET1" I just want to write it somewhere. All tips are appreciated

Thanks,

Franz

  • Cancel
Parents
  • p94todorov
    p94todorov over 2 years ago

    Hi Franz,

    you can try with numberp(cdfParseFloatString(string1)).

    Regards,

    Petar

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • FranzD
    FranzD over 2 years ago in reply to p94todorov

    Thank you very much. That was exactly the function I was looking for.

    Regards,

    Franz

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • AaronSymko
    AaronSymko over 2 years ago in reply to FranzD

    Another option is to use:

    numberp(aelNumber(string1))

    However, in certain cases (e.g. pcell code), using cdfParseFloatString() may be preferred.

    Regards,

    -Aaron

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • FranzD
    FranzD over 2 years ago in reply to AaronSymko

    I tried aelNumber() before to test if its a float, but I always get Warnings when its not. The function mentioned before fits good for me. But I now discovered another problem: I not only need to check if its float or string but also if the string is an integer. Any suggestions for this? My main goal is to create CDF parameter variation of different cells. For this I read an check the parameters type and then decide how to variy them.

    Thanks for you replies

    Franz

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 2 years ago in reply to FranzD

    Franz,

    I did originally think that maybe using atoi() would be the best approach, but since atoi("5u") returns 5, maybe that's not the best option. You might need to just do: pcreMatchp("^\\d+$" val)&&atoi(val)

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • FranzD
    FranzD over 2 years ago in reply to Andrew Beckett

    Ok I used it and it seems to do what I need. I now check first with numberp(cdfParseFloatString(val) if val is a number, then check if val is integer or not with  pcreMatchp("^\\d+$" val)&&atoi(val). Thank you all for your help!

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 2 years ago in reply to FranzD

    Hi Franz,

    By the way, you only really need to use the &&atoi(val) part if you want to return it as an integer; if you're just checking, then the pcreMatchp() would be sufficient.

    Regards,

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • FranzD
    FranzD over 2 years ago in reply to Andrew Beckett

    Hi Andrew, 

    I also thought that since atoi(string) returns nil when string is not an integer, that this would be sufficient. I wanna test if its an integer and if so also do some calculations with it. My calcultaions are depending on the number type of the string. So I use different values for a float then for the iteger number. Since I check with numberp(cdfParseFloatString(string)) if string is a number it is then sufficient to use atoi(string) to check if string is an integer. If not so it must be a float. Is this right or do I miss something here?

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • FranzD
    FranzD over 2 years ago in reply to FranzD

    Ok its not working only with atoi(). I need the pcreMatchp()&&atoi() also. Then it does everthing I want.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 2 years ago in reply to FranzD
    FranzD said:
    Ok its not working only with atoi(). I need the pcreMatchp()&&atoi() also. Then it does everthing I want.

    The problem is that numberp(cdfParseFloatString(string)) and atoi(string) would both return true (at least, non-nil) for both "5u" and "5". So it doesn't help to distinguish between the two. If atoi() had returned nil if there were any non-digit characters in the string, it would have been fine, but it doesn't, so that isn't a solution... hence the pcreMatchp suggestion.

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 2 years ago in reply to FranzD
    FranzD said:
    Ok its not working only with atoi(). I need the pcreMatchp()&&atoi() also. Then it does everthing I want.

    The problem is that numberp(cdfParseFloatString(string)) and atoi(string) would both return true (at least, non-nil) for both "5u" and "5". So it doesn't help to distinguish between the two. If atoi() had returned nil if there were any non-digit characters in the string, it would have been fine, but it doesn't, so that isn't a solution... hence the pcreMatchp suggestion.

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information