Distinguish a floating-point argument from an integer?

20 views
Skip to first unread message

Brandon Harvey

unread,
Oct 15, 2012, 11:25:00 PM10/15/12
to v8-u...@googlegroups.com
I'd like to be able to know whether not a particular  Local<Value> (passed to me as part of any Arguments list) refers to an integral number (e.g. 5) or a floating-point style number (e.g. 5.0).  Is there any way to make that distinction?

Vyacheslav Egorov

unread,
Oct 16, 2012, 1:22:50 AM10/16/12
to v8-u...@googlegroups.com

There are no integers in JavaScript so semantically they are identical. It's an implementation detail that 5.0 is sometimes represented as 5. Why do you want to distinguish them?

Vyacheslav Egorov

On Oct 16, 2012 5:25 AM, "Brandon Harvey" <sand...@gmail.com> wrote:
I'd like to be able to know whether not a particular  Local<Value> (passed to me as part of any Arguments list) refers to an integral number (e.g. 5) or a floating-point style number (e.g. 5.0).  Is there any way to make that distinction?

Brandon Harvey

unread,
Oct 16, 2012, 1:31:08 PM10/16/12
to v8-u...@googlegroups.com
I'd like to be able to do printf / snprintf style string formatting, on the C++ side, using numbers obtained from v8.  However, I'm not sure how to know whether to use %f or %d (etc.) in any given case.  I'd like to be able to reflect the intent of the Javascript writer -- if they wrote 5.0, I'd like to use %f, and if they wrote 5, I'd like to use %d.

Brandon

Vyacheslav Egorov

unread,
Oct 16, 2012, 11:30:07 PM10/16/12
to v8-u...@googlegroups.com

No this is not possible. No matter what they write in the source 5 or 5.0 it'll be represented as 5.

Vyacheslav Egorov

Reply all
Reply to author
Forward
0 new messages