tags:

views:

34

answers:

2

Hi there,

When using jquery's offset method on an element to get its top offset from the document, it returns me the following for example:

1150.3999938964844

Is there a reason why it does that, and doesn't return a whole number?

Thanks

A: 

If it has any dimensions defined as percentages (or any parent does really, unless it's out of the flow) for instance....there's no guarantee it's a whole number :)

Nick Craver
All widths/heights have been declared as pixels, guess I can use math.round to eliminate this. Odd though. Thanks
Rishi
@Rishi - Do you have an example page I can see?, I could tell you where it's coming from then.
Nick Craver
A: 

Is there a reason why it does that, and doesn't return a whole number?

jQuery.fn.offset = function( options ) {

...

parseFloat( ... )

...
  • jQuery source

See also: Floating Point Accuracy Problems at Wikipedia

danlefree