Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #18942

Re: FAQ Topic - How do I format a Number as a String with exactly 2 decimal places? (2013-03-15)

Newsgroups comp.lang.javascript
Subject Re: FAQ Topic - How do I format a Number as a String with exactly 2 decimal places? (2013-03-15)
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <51426487$0$32115$14726298@news.sunsite.dk> <XnsA18460B31AE76eejj99@194.109.133.133> <aZewtRTO6MRRFw0Z@invalid.uk.co.demon.merlyn.invalid> <XnsA186C77818CE7eejj99@194.109.133.133> <qVd8etJBl2RRFwyr@invalid.uk.co.demon.merlyn.invalid>
Date 2013-03-19 08:43 +0100
Message-ID <XnsA18858CCDC3ECeejj99@194.109.133.133> (permalink)

Show all headers | View raw


Dr J R Stockton wrote on 18 mrt 2013 in comp.lang.javascript:

> In comp.lang.javascript message <XnsA186C77818CE7eejj99@194.109.133.133>
> , Sun, 17 Mar 2013 19:36:30, Evertjan. <exxjxw.hannivoort@inter.nl.net>
> posted:
> 
> 
>>No reason why it should work with null.
>>Should it work for n = 'blah';,
>>or for n being an object?
> 
> A FAQ Number formatting routine should give correct results for all
> values of the type Number.  Users who have confidence (often misplaced)
> that some values will not occur can simplify the code if they need to.

I do not agree at all.
 
> For pedagogical reasons, 

... examples in the faq should not concern themselves with any code that 
is not directly necessary to demonstrate the desired effect.

A FAQ is to learn form, not to copy without understanding.

> maybe the FAQ answer should include an initial
> test, commented out, that the input is indeed a Number.  With your
> (original) code,   formatNumber2(formatNumber2)   returns NaN, 

I have no idea why formatNumber(), which by definition should return a 
string, should be able to have itself as a parameter, where logic suggests 
the parameter must be a number.

> which is not ideal.  

Why?

> The result of a function call should never be misleading.

The FAQ is for teaching. Misleadingnees is a fact of programming life, and 
should be taught, even in the FAQ-examples.

The only strict necessity [see disclaimer] of a formatter is, that it 
returns a string and that it can depand on getting parameters of described 
types.

A formatter formatMyNumber(num, decs) should not test if the decs value 
realy is a number and not a text-string like "six". At least not in the 
FAQ. even while it is perfectly possible to make this function understand 
the named string and correct for spelling-errors.

The reader wants, he could add lines forbidding negative numbers less than 
-3.96, and changing those values to an informative test-string, but such 
lines should NOT be part of the FAQ, as it makes newbees wanting to learn 
something changing their primary interest away from Javascript to 
needlework.

Your pages, which nowadays would be published as blogs [don't please], are 
a much better place to show these more intricate but very usefull examples 
you propose. The FAQ could point to them where appropriate.
 
> My Web site includes good, indifferent, and bad formatters.

Quite, but subjective in judgement. 
The FAQ should give the bare example.

Disclaimer: My ideas are not necessarily the ideas of the somewhere 
university school of matheinformatics, but then again by pure chance some 
might be.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

FAQ Topic - How do I format a Number as a String with exactly 2 decimal places? (2013-03-15) "FAQ server" <javascript@dotinternet.be> - 2013-03-15 00:00 +0000
  Re: FAQ Topic - How do I format a Number as a String with exactly 2 decimal places? (2013-03-15) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-03-15 09:30 +0100
    Re: FAQ Topic - How do I format a Number as a String with exactly 2 decimal places? (2013-03-15) Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-03-16 19:57 +0000
      Re: FAQ Topic - How do I format a Number as a String with exactly 2 decimal places? (2013-03-15) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-03-17 19:36 +0100
        Re: FAQ Topic - How do I format a Number as a String with exactly 2 decimal places? (2013-03-15) Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-03-18 19:21 +0000
          Re: FAQ Topic - How do I format a Number as a String with exactly 2 decimal places? (2013-03-15) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-03-19 08:43 +0100

csiph-web