Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

trimming a long in java

  • 25-11-2003 06:45PM
    #1
    Closed Accounts Posts: 1,152 ✭✭✭


    hey all,

    i have this problem with my java program. i have to limit the number of digits in a long to 10, i have thought of ways to do this such as checking if the number is greater than 999,999,999. would this work?

    any help much appreciated


Comments

  • Hosted Moderators Posts: 2,094 ✭✭✭halenger


    You're problem there would be this:

    99.9999999999999 etc would always be smaller than 999,999,999!

    instead of checking the size of try:

    [PHP]if (long.toString().length() < 10)
    proceed;[/PHP]

    Hope this suits you.


  • Closed Accounts Posts: 1,152 ✭✭✭sound_wave


    thanks halenger, that worked a treat. thanks once again


Advertisement