in reply to Re^3: How to determine whether a number has a decimal component?
in thread How to determine whether a number has a decimal component?

Ok, i'll try to give a simple explanation. I was drawing a graph with GD::Graph and would like to restrict the the y-ticks so they only get drawn on values like these: 1, 1.5, 2, 2.5, etc. The number of ticks was pre-set.

I've since gone another way that dispenses with this completely, but still thought it would be something nice to meditate over, especially as i couldn't find a solution that didn't fall afoul any of these: I was hoping i'd missed something and someone would point out some inbuilt "has_decimal" function in Perl or something, but apparently no such thing exists.
  • Comment on Re^4: How to determine whether a number has a decimal component?

Replies are listed 'Best First'.
Re^5: How to determine whether a number has a decimal component?
by swampyankee (Parson) on Jan 04, 2009 at 22:40 UTC

    There are algorithms out there to find "nice" scales for graphs; I'd suggest one of them. You can find one routine to do so here. It's from the Griffiths and Hill archive at Carnegie-Mellon's StatLib site. More may be found here or at CGAL.


    Another is from the Graphics Gems web site.


    Information about American English usage here and here. Floating point issues? Please read this before posting. — emc