[jQuery] Re: how to change 2,5 to 2,50 ?

2009-07-08 Thread Massimo Lombardo

Yeah, that's what I mean ;)

That's why I explicitly cited IEEE754 in my reply instead of saying
something like «heh, you know, it's that weird javascript thing with
numbers» :)

On Wed, Jul 8, 2009 at 04:53, RobGrobg...@gmail.com wrote:



 On Jul 7, 9:14 pm, Massimo Lombardo unwiredbr...@gmail.com wrote:
 [...]
 As I see you're dealing with cents, money and stuff, I have to
 remember you that JavaScript use IEEE 754 Floating Points as its own
 internal number type, so 0.1 + 0.2 !== 0.3: people tend to be very
 picky when dealing with money, especially if it's *their* money! :)

 So: be careful. And if you're relying on JavaScript logic to handle
 people's money, change programming language, JavaScript is not good at
 it.

 The language is not the issue as such, any language using IEEE-754
 numbers will have exactly the same problem - certain decimal values
 can't be represented exactly.  The solution is to understand the issue
 and deal with it, not live in fear.

 URL: http://www.jibbering.com/faq/#binaryNumbers 


 --
 Rob
-- 
Massimo Lombardo
Linux user #437712


[jQuery] Re: how to change 2,5 to 2,50 ?

2009-07-07 Thread weidc

solved it by myself.

endpreis =Math.round(endpreis*100)/100;
endpreis = endpreis+ foo;
endpreis = endpreis.replace(/ foo/,);
var cent = endpreis.split(.);

if(cent[1].length == 1)
{
endpreis = endpreis+0;
}else{
if(cent[1].length == 2)
{
//schoen so
}else{
endpreis = endpreis+.00;
}
}

On 7 Jul., 12:11, weidc mueller.juli...@googlemail.com wrote:
 hi,

 thats my code:

 endpreis =Math.round(endpreis*100)/100;

 to round the price of something but i'd like to have 2,00 or 2,50
 instead of 2 and 2,5.

 i'd be happy about any help.

 --weidc


[jQuery] Re: how to change 2,5 to 2,50 ?

2009-07-07 Thread jeff
ha ha good work

:)

On Tue, Jul 7, 2009 at 4:29 PM, weidc mueller.juli...@googlemail.comwrote:


 solved it by myself.

 endpreis =Math.round(endpreis*100)/100;
 endpreis = endpreis+ foo;
 endpreis = endpreis.replace(/ foo/,);
 var cent = endpreis.split(.);

 if(cent[1].length == 1)
 {
endpreis = endpreis+0;
 }else{
if(cent[1].length == 2)
{
//schoen so
}else{
endpreis = endpreis+.00;
}
 }

 On 7 Jul., 12:11, weidc mueller.juli...@googlemail.com wrote:
  hi,
 
  thats my code:
 
  endpreis =Math.round(endpreis*100)/100;
 
  to round the price of something but i'd like to have 2,00 or 2,50
  instead of 2 and 2,5.
 
  i'd be happy about any help.
 
  --weidc




-- 
-- 
(¨`•.•´¨) I may be busy,
`•.¸(¨`•.•´¨)  but I assure you,
(¨`•.•´¨)¸.•´ you are always in my heart
`•.¸.•´


With Lots of Love.

THANKS AND REGARDS

Jeffery Jacob


[jQuery] Re: how to change 2,5 to 2,50 ?

2009-07-07 Thread Massimo Lombardo

This one is more general (and faster, I think: no if-else, no regexp)

Number.prototype.padRight = function (fill) {
var v = this.toString().split('.'), d = v[1] || '';
return (v[0] || '0') + '.' + d + fill.substr(d.length);
}

test1 = 2;
test2 = 3.141592;
test3 = 0.001;
test4 = .33;

test1.padRight('00'); // returns 2.00
test2.padRight('00'); // returns 3.141592
test3.padRight('00'); // returns 0.001
test4.padRight('00'); // returns 0.33

As I see you're dealing with cents, money and stuff, I have to
remember you that JavaScript use IEEE 754 Floating Points as its own
internal number type, so 0.1 + 0.2 !== 0.3: people tend to be very
picky when dealing with money, especially if it's *their* money! :)

So: be careful. And if you're relying on JavaScript logic to handle
people's money, change programming language, JavaScript is not good at
it.

On Tue, Jul 7, 2009 at 12:11, weidcmueller.juli...@googlemail.com wrote:

 hi,

 thats my code:

 endpreis =Math.round(endpreis*100)/100;

 to round the price of something but i'd like to have 2,00 or 2,50
 instead of 2 and 2,5.


 i'd be happy about any help.

 --weidc
-- 
Massimo Lombardo
Linux user #437712


[jQuery] Re: how to change 2,5 to 2,50 ?

2009-07-07 Thread weidc

no it's not for money + - money. it's just to show the price of
something - % action in different sizes after selecting something in
dropdown options. everything else is with php of course. but i'll try
your way too. :)

On 7 Jul., 13:14, Massimo Lombardo unwiredbr...@gmail.com wrote:
 This one is more general (and faster, I think: no if-else, no regexp)

 Number.prototype.padRight = function (fill) {
     var v = this.toString().split('.'), d = v[1] || '';
     return (v[0] || '0') + '.' + d + fill.substr(d.length);

 }

 test1 = 2;
 test2 = 3.141592;
 test3 = 0.001;
 test4 = .33;

 test1.padRight('00'); // returns 2.00
 test2.padRight('00'); // returns 3.141592
 test3.padRight('00'); // returns 0.001
 test4.padRight('00'); // returns 0.33

 As I see you're dealing with cents, money and stuff, I have to
 remember you that JavaScript use IEEE 754 Floating Points as its own
 internal number type, so 0.1 + 0.2 !== 0.3: people tend to be very
 picky when dealing with money, especially if it's *their* money! :)

 So: be careful. And if you're relying on JavaScript logic to handle
 people's money, change programming language, JavaScript is not good at
 it.

 On Tue, Jul 7, 2009 at 12:11, weidcmueller.juli...@googlemail.com wrote:

  hi,

  thats my code:

  endpreis =Math.round(endpreis*100)/100;

  to round the price of something but i'd like to have 2,00 or 2,50
  instead of 2 and 2,5.

  i'd be happy about any help.

  --weidc

 --
 Massimo Lombardo
 Linux user #437712


[jQuery] Re: how to change 2,5 to 2,50 ?

2009-07-07 Thread Giovanni Battista Lenoci


weidc ha scritto:

no it's not for money + - money. it's just to show the price of
something - % action in different sizes after selecting something in
dropdown options. everything else is with php of course. but i'll try
your way too. :)
  


As a (mainly) php programmer I think this site is fantastic:

http://phpjs.org/functions/str_pad:525

http://phpjs.org/functions/number_format:481

Bye :-)



--
gianiaz.net - web solutions
via piedo, 58 - 23020 tresivio (so) - italy
+39 347 7196482 



[jQuery] Re: how to change 2,5 to 2,50 ?

2009-07-07 Thread weidc

the price have to change on the page without reloading the site. the
javascript is just to look well for the customers. but thank you
anyway!

On 7 Jul., 13:24, Giovanni Battista Lenoci gian...@gmail.com wrote:
 weidc ha scritto:

  no it's not for money + - money. it's just to show the price of
  something - % action in different sizes after selecting something in
  dropdown options. everything else is with php of course. but i'll try
  your way too. :)

 As a (mainly) php programmer I think this site is fantastic:

 http://phpjs.org/functions/str_pad:525

 http://phpjs.org/functions/number_format:481

 Bye :-)

 --
 gianiaz.net - web solutions
 via piedo, 58 - 23020 tresivio (so) - italy
 +39 347 7196482


[jQuery] Re: how to change 2,5 to 2,50 ?

2009-07-07 Thread RobG



On Jul 7, 8:11 pm, weidc mueller.juli...@googlemail.com wrote:
 hi,

 thats my code:

 endpreis =Math.round(endpreis*100)/100;

 to round the price of something but i'd like to have 2,00 or 2,50
 instead of 2 and 2,5.

 i'd be happy about any help.

To format a number in javascript with exactly two decimal places it is
a good idea to try a resource dedicated to javascript:

URL: http://www.jibbering.com/faq/#formatNumber 


--
Rob


[jQuery] Re: how to change 2,5 to 2,50 ?

2009-07-07 Thread Giovanni Battista Lenoci


weidc ha scritto:

the price have to change on the page without reloading the site. the
javascript is just to look well for the customers. but thank you
anyway!
  

Yes, the functions I've posted are javascript trasposition of php functions.

In php exists the number format function: |$number = 1000; echo 
number_format($number, 2, ',', '.'); // 1.000,00
After including the javascript function I've linked you can use the same 
syntax.


Bye
|

--
gianiaz.net - web solutions
via piedo, 58 - 23020 tresivio (so) - italy
+39 347 7196482 



[jQuery] Re: how to change 2,5 to 2,50 ?

2009-07-07 Thread Cesar Sanz


Massimos'

Number.prototype.padRight = function (fill) {
   var v = this.toString().split('.'), d = v[1] || '';
   return (v[0] || '0') + '.' + d + fill.substr(d.length);
}

Very elegant solution!!

- Original Message - 
From: Giovanni Battista Lenoci gian...@gmail.com

To: jquery-en@googlegroups.com
Sent: Tuesday, July 07, 2009 7:30 AM
Subject: [jQuery] Re: how to change 2,5 to 2,50 ?




weidc ha scritto:

the price have to change on the page without reloading the site. the
javascript is just to look well for the customers. but thank you
anyway!

Yes, the functions I've posted are javascript trasposition of php 
functions.


In php exists the number format function: |$number = 1000; echo 
number_format($number, 2, ',', '.'); // 1.000,00
After including the javascript function I've linked you can use the same 
syntax.


Bye
|

--
gianiaz.net - web solutions
via piedo, 58 - 23020 tresivio (so) - italy
+39 347 7196482 




[jQuery] Re: how to change 2,5 to 2,50 ?

2009-07-07 Thread Massimo Lombardo

Thank you :)

On Tue, Jul 7, 2009 at 16:46, Cesar Sanzthe.email.tr...@gmail.com wrote:

 Massimos'

 Number.prototype.padRight = function (fill) {
   var v = this.toString().split('.'), d = v[1] || '';
   return (v[0] || '0') + '.' + d + fill.substr(d.length);
 }

 Very elegant solution!!
-- 
Massimo Lombardo
Linux user #437712


[jQuery] Re: how to change 2,5 to 2,50 ?

2009-07-07 Thread mkmanning

There are also some currency formatting plugins:

http://plugins.jquery.com/project/currencyFormat

(or search currency under plugins)

On Jul 7, 3:11 am, weidc mueller.juli...@googlemail.com wrote:
 hi,

 thats my code:

 endpreis =Math.round(endpreis*100)/100;

 to round the price of something but i'd like to have 2,00 or 2,50
 instead of 2 and 2,5.

 i'd be happy about any help.

 --weidc


[jQuery] Re: how to change 2,5 to 2,50 ?

2009-07-07 Thread RobG



On Jul 8, 1:59 am, mkmanning michaell...@gmail.com wrote:
 There are also some currency formatting plugins:

 http://plugins.jquery.com/project/currencyFormat

That appears to make extensive use of toFixed(), which is known to be
buggy in some browsers for certain values.  Try:

  alert( (0.0625).toFixed(1) );

Firefox shows 0.1 (correct)
IE 6 shows 0.0 (wrong).

URL: http://www.merlyn.demon.co.uk/js-rndg1.htm 


--
Rob


[jQuery] Re: how to change 2,5 to 2,50 ?

2009-07-07 Thread RobG



On Jul 7, 9:14 pm, Massimo Lombardo unwiredbr...@gmail.com wrote:
[...]
 As I see you're dealing with cents, money and stuff, I have to
 remember you that JavaScript use IEEE 754 Floating Points as its own
 internal number type, so 0.1 + 0.2 !== 0.3: people tend to be very
 picky when dealing with money, especially if it's *their* money! :)

 So: be careful. And if you're relying on JavaScript logic to handle
 people's money, change programming language, JavaScript is not good at
 it.

The language is not the issue as such, any language using IEEE-754
numbers will have exactly the same problem - certain decimal values
can't be represented exactly.  The solution is to understand the issue
and deal with it, not live in fear.

URL: http://www.jibbering.com/faq/#binaryNumbers 


--
Rob