473,771 Members | 2,406 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FAQ Topic - Why does K = parseInt('09') set K to 0?

-----------------------------------------------------------------------
FAQ Topic - Why does K = parseInt('09') set K to 0?
-----------------------------------------------------------------------

The parseInt function decides what base the number is by
looking at the number. It assumes that any number beginning
with '0x' or '0X' is hexadecimal, but it has a choice with a
leading zero: the number can either be octal or decimal.
Assuming octal, the string '09' will be converted to 0 (octal
digits are 0-7); assuming decimal, '09' will be converted to 9
(the leading zero is ignored).
To force use of a particular base, add a second parameter:
« parseInt("09",b ase) »

http://msdn.microsoft.com/library/en...thparseint.asp

http://docs.sun.com/source/816-6408-...ev.htm#1064173

http://www.jibbering.com/faq/faq_not....html#FAQN4_12
===
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javas cript FAQ is at http://www.jibbering.com/faq/.
The FAQ workers are a group of volunteers.

Dec 19 '06
14 2982
Dr J R Stockton said the following on 12/20/2006 6:40 PM:
In comp.lang.javas cript message <rt************ ********@telcov e.net>,
Tue, 19 Dec 2006 21:17:17, Randy Webb <Hi************ @aol.comwrote:
>Dr J R Stockton said the following on 12/19/2006 5:18 PM:
>>In comp.lang.javas cript message
<45********** *************@n ews.sunsite.dk> , Tue, 19 Dec 2006 00:00:02,
FAQ server <ja********@dot internet.bewrot e:
-----------------------------------------------------------------------
FAQ Topic - Why does K = parseInt('09') set K to 0?
-----------------------------------------------------------------------

The parseInt function decides what base the number is by
looking at the number. It assumes that any number beginning
with '0x' or '0X' is hexadecimal, but it has a choice with a
leading zero: the number can either be octal or decimal.
Assuming octal, the string '09' will be converted to 0 (octal
digits are 0-7); assuming decimal, '09' will be converted to 9
(the leading zero is ignored).
To force use of a particular base, add a second parameter:
‹ parseInt("09",b ase) ›
The text does not really answer the Subject question.

Why not? It explains how parseInt deals with the first parameter,
which is what the question was intended to answer.

While your responses are correctly interleaved with what you quote, it
is an error to immediately question a paragraph which is explained and
justified in the following quoted paragraph.
No, the error is to think you use common sense when you post.

I am beginning to realize why Richard ignored so many of your FAQ
Requests. The current wording of that question was a result of a direct
request by you to change it to it's current wording and now you are
saying it is wrong. Make up your mind.

<snip>
>But that issue seems to be Date related, not parseInt related or does
the Date Object use parseInt to read its parameters?
>>So I suggest a final paragraph to that FAQ section -
"A literal L in the source is read as if by parseInt(L), so 012 means
ten." - or whatever similar covers all cases.

"The same rules apply to the Base parameter as apply to the first
parameter" or similar?

NO. ICBW, but ISTM that a literal base parameter is treated as any
other literal. Therefore, it would be wrong to make a remark
specifically about the base parameter.
Then there will be no remark at all.
>>A better Subject might be "Why is my 09 read as Zero?" - it accommodates
more.

But it doesn't cover - directly - the issue with using parseInt on
"09" or the likes.


Indeed it does cover it; though it does not cover 012 being read as ten.
Why answer a narrow question when a broader one would, without needing
to say much more, deal with the full range of similar cases?

Subject "Why are Strings beginning with a zero digit sometimes read as
unexpected integer Numbers?"
Do you honestly believe that people looking for an answer to
parseInt('09') being set to zero are going to look at a question phrased
as you have it there? The FAQ is intended - or it should be - for people
trying to learn from it, not from Anally Retentive know-it-alls that
want a quick personal reference document.

Unless there is some other problem with that entry (from someone besides
you), it will stay worded the way it is - along with the question.

I am not going to argue pedantic BS with you.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 21 '06 #11
In comp.lang.javas cript message <Co************ ********@telcov e.net>,
Thu, 21 Dec 2006 10:32:41, Randy Webb <Hi************ @aol.comwrote:
>Dr J R Stockton said the following on 12/20/2006 6:40 PM:
>In comp.lang.javas cript message <rt************ ********@telcov e.net>,
Tue, 19 Dec 2006 21:17:17, Randy Webb <Hi************ @aol.comwrote:
>>Dr J R Stockton said the following on 12/19/2006 5:18 PM:
In comp.lang.javas cript message
<45********* **************@ news.sunsite.dk >, Tue, 19 Dec 2006 00:00:02,
FAQ server <ja********@dot internet.bewrot e:
-----------------------------------------------------------------------
FAQ Topic - Why does K = parseInt('09') set K to 0?
-----------------------------------------------------------------------
>
The parseInt function decides what base the number is by
looking at the number. It assumes that any number beginning
with '0x' or '0X' is hexadecimal, but it has a choice with a
leading zero: the number can either be octal or decimal.
Assuming octal, the string '09' will be converted to 0 (octal
digits are 0-7); assuming decimal, '09' will be converted to 9
(the leading zero is ignored).
To force use of a particular base, add a second parameter:
‹ parseInt("09",b ase) ›
The text does not really answer the Subject question.

Why not? It explains how parseInt deals with the first parameter,
which is what the question was intended to answer.
While your responses are correctly interleaved with what you quote,
it is an error to immediately question a paragraph which is explained
and justified in the following quoted paragraph.

No, the error is to think you use common sense when you post.

I am beginning to realize why Richard ignored so many of your FAQ
Requests. The current wording of that question was a result of a direct
request by you to change it to it's current wording and now you are
saying it is wrong. Make up your mind.
Richard ignored all FAQ requests, independently of perceived merit. Is
that better or worse than lacking the ability to perceive merit?
><snip>
>>>So I suggest a final paragraph to that FAQ section -
"A literal L in the source is read as if by parseInt(L), so 012 means
ten." - or whatever similar covers all cases.

"The same rules apply to the Base parameter as apply to the first
parameter" or similar?
NO. ICBW, but ISTM that a literal base parameter is treated as any
other literal. Therefore, it would be wrong to make a remark
specificall y about the base parameter.

Then there will be no remark at all.
>>>A better Subject might be "Why is my 09 read as Zero?" - it accommodates
more.

But it doesn't cover - directly - the issue with using parseInt on
"09" or the likes.
Indeed it does cover it; though it does not cover 012 being read as
ten. Why answer a narrow question when a broader one would, without
needing to say much more, deal with the full range of similar cases?
> Subject "Why are Strings beginning with a zero digit sometimes read
as unexpected integer Numbers?"

Do you honestly believe that people looking for an answer to
parseInt('09 ') being set to zero are going to look at a question
phrased as you have it there?
That Subject covers their problem; they have a string beginning with
zero, and they get unexpected answers. The present Subject line,
admittedly an improvement on its predecessor, will not appear to be
relevant to someone who finds that parseInt('044') gives thirty-six,
nor to someone who is using 012 as a literal and does not want ten.

>I am not going to argue pedantic BS with you.
You are unable to accept correction, and persistently argue with those
of broader experience than yourself. Therefore, you will be unable to
honour that promise.

--
(c) John Stockton, Surrey, UK. ??*@merlyn.demo n.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demo n.co.uk/- FAQish topics, acronyms, & links.

Food expiry ambiguities: <URL:http://www.merlyn.demo n.co.uk/date2k-3.htm#Food>
Dec 21 '06 #12
Dr J R Stockton said the following on 12/21/2006 5:41 PM:
In comp.lang.javas cript message <Co************ ********@telcov e.net>,
Thu, 21 Dec 2006 10:32:41, Randy Webb <Hi************ @aol.comwrote:
>Dr J R Stockton said the following on 12/20/2006 6:40 PM:
<snip>
>I am beginning to realize why Richard ignored so many of your FAQ
Requests. The current wording of that question was a result of a
direct request by you to change it to it's current wording and now you
are saying it is wrong. Make up your mind.

Richard ignored all FAQ requests, independently of perceived merit. Is
that better or worse than lacking the ability to perceive merit?
Without confirmation from Richard that he did indeed ignore them rather
than read them and dismiss them, I don't see how you can make the claim
in your first sentence and that makes your question moot to me.

<snip>
>Do you honestly believe that people looking for an answer to
parseInt('09 ') being set to zero are going to look at a question
phrased as you have it there?

That Subject covers their problem; they have a string beginning with
zero, and they get unexpected answers. The present Subject line,
admittedly an improvement on its predecessor, will not appear to be
relevant to someone who finds that parseInt('044') gives thirty-six,
nor to someone who is using 012 as a literal and does not want ten.
And when that happens, they ask and get directed to that entry. They
read it and see the answer to the question. The solution is quite
simple, and you have argued with me in the past about how simple it is -
always supply a radix/base to parseInt and you won't have a problem.
>
>I am not going to argue pedantic BS with you.

You are unable to accept correction,
That is, without a doubt, one of the dumbest things I have ever read
that you wrote.
and persistently argue with those of broader experience than yourself.
If the experience you are referring to is in the area of being a
pedantically anal retentive poster, you are right, you have a lot
broader experience at than I do.

<snip>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 22 '06 #13
Randy Webb wrote:
Michael Winter said the following on 12/19/2006 3:44 PM:
[snip]
>A string doesn't have to begin with '0x' or '0X' to be treated as
hexadecimal; it does have '0x' or '0X' as the first non-white space
characters.

What do you think about the proposed re-wording?
That you posted in reply to Julian? It's OK. The last point I noted
above is difficult to convey succinctly, and I'm not sure how to write
that part well.

[snip]
>The FAQ is currently sent with a "Cache-Control: private" header
name/value pair and no cache validators. It would nice if this were
changed so visitors don't have to download the FAQ again unless
it's been modified. The private Cache-Control directive doesn't
necessarily restrict a user agent cache, but does unnecessarily
prevent shared caches from storing the entity.

I will leave that to Jim to change/correct as it is outside the
bounds of my access to the server.
And it has been. Thank you both.

Mike
Dec 28 '06 #14
Michael Winter said the following on 12/28/2006 11:17 AM:
Randy Webb wrote:
>Michael Winter said the following on 12/19/2006 3:44 PM:

[snip]
>>A string doesn't have to begin with '0x' or '0X' to be treated as
hexadecimal ; it does have '0x' or '0X' as the first non-white space
characters.

What do you think about the proposed re-wording?

That you posted in reply to Julian? It's OK. The last point I noted
above is difficult to convey succinctly, and I'm not sure how to write
that part well.
I have changed it to the proposed posting in my reply to Julian.

<new wording locally>
The parseInt function decides what base to
convert a number represented as a string
to by looking at the string. It assumes that
any string beginning with '0x' or '0X' represents
a hexadecimal number, but it has a choice with a
leading zero: the string could represent a number
that can be either octal or decimal. Assuming
octal, the string '09' will be converted to 0
(octal digits are 0-7); assuming decimal, '09'
will be converted to 9 (the leading zero is
ignored). To force use of a particular base,
add a second parameter:
parseInt("09",b ase).
</new wording locally>

I probably won't upload another 9.xx series of the FAQ but it will be in
the proposed 10.x version. I will try, after 10.x gets finished, to
get a new wording for it that will reflect the leading whitespace issue
(probably make it a Notes page).

Thank you.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 30 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
9598
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does parseInt('09') give an error? ----------------------------------------------------------------------- The parseInt function decides what base the number is by looking at the number. By convention it assumes that any number beginning with 0x is Hexadecimal, and otherwise any number beginning with 0 is Octal. To force use of base 10 add a second...
1
338
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does K = parseInt('09') set K to 0? ----------------------------------------------------------------------- The parseInt function decides what base to convert a number represented as a string to by looking at the string. It assumes that any string beginning with '0x' or '0X' represents a hexadecimal number, but it has a choice with a leading zero:...
0
9619
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10102
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9910
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.