[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A Contest

At 04:50 AM 3/3/96 -0500, Ellie wysiwyg wrote:
>To All:
>I hereby declare a contest, the winner wins the resault amount in dollars !!!
>Terms:He who first finds a 'fix' to the following script, so it gives the
>correct answer(by the widespread euclidean system). AND explains the
>existing resualt.
>Here it is:
>The check is waiting for YOU !

Here it is!

// Permission to use/change this code is granted for all purposes
// as long as this header remains in tact.
// Parameters --
//   input  -- pass in any number (int,float)
//   output -- returns a STRING rounded off to 100ths place
//  (C) 1996 Andy Augustine for Frequency Graphics 3.1.96
function moneyFormat(input) {
 var output = 0    // tried to force a # by typing
 var dollars = Math.floor(input)
 var cents  = "" + Math.round(input * 100)
 cents = cents.substring (cents.length-2, cents.length)
 input = dollars + "." + cents
 output = input
 return (output)

var temp = (.85 - .05)
// -->

The first attempt in this code was to 'type' output as a number (float/int)
so that when it was assigned the value of input, it would be represented as
a number.  The problem lies in the fact that parseFloat is internally called
(I assume) when you try to say "output = 1 * (0 + input)".  But all you
wanted was to be able to write() the result (instead of return a
non-string), and my function does that.

BTW.. more on this available at JavaScript 411.

Andy Augustine

For help about the list, please send a message to 'majordomo@obscure.org'
with the message body 'help'. To unsubscribe, send a message to
'majordomo@obscure.org' with the message body 'unsubscribe javascript'.
List archives and pointer to FAQ: http://www.obscure.org/javascript/