[Proto-Scripty] Re: Decimal places
reply thanks that worked I had to remember to add the quotes around my response to make it a string. I'll also keep the calulation in mind if I have any issues, so far all math is done in external programs and sent back as a response. On Mar 5, 8:15 pm, RobG rg...@iinet.net.au wrote: On Mar 5, 7:50 am, Bob bro...@packagingcorp.com wrote: I'm relativley new to PrototypeJS. I am doing some calculation in a back end program and returning a JSON string to my web page. One of the values is a price. If I return 14.20, it gets converted in evalJSON to 14.2. I want to keep both digits. I can find how to pad the left of a nmber to a certain number of places, but can't seem to find anythig about keeping decimals out to a set number of places. Others have answered your question (pass the value as a string), here's a bit more information on the topic if you are doing in-page calculations and wondering why they don't quite add up: How do I format a Number as a String with exactly 2decimalplaces? URL:http://www.jibbering.com/faq/#formatNumber -- Rob --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Decimal places
On Wed, 2009-03-04 at 13:50 -0800, Bob wrote: I'm relativley new to PrototypeJS. I am doing some calculation in a back end program and returning a JSON string to my web page. One of the values is a price. If I return 14.20, it gets converted in evalJSON to 14.2. I want to keep both digits. I can find how to pad the left of a nmber to a certain number of places, but can't seem to find anythig about keeping decimals out to a set number of places. Just a guess: Convert to a string and then back to a number as needed? -- Matt Zagrabelny - mzagr...@d.umn.edu - (218) 726 8844 University of Minnesota Duluth Information Technology Systems Services PGP key 1024D/84E22DA2 2005-11-07 Fingerprint: 78F9 18B3 EF58 56F5 FC85 C5CA 53E7 887F 84E2 2DA2 He is not a fool who gives up what he cannot keep to gain what he cannot lose. -Jim Elliot signature.asc Description: This is a digitally signed message part
[Proto-Scripty] Re: Decimal places
Hi, If you're passing it as a numeric literal, e.g.: { price: 14.20 } ...what you're dealing with is a number, which you'll later *render* as a string for display. All JavaScript numbers have the same precision, which I'm not quite geeky enough to quote you. ;-) You'll need to handle formatting at the presentation stage. Since these are prices, formatting is pretty straightforward, as the precision doesn't vary from one price to the next. If you needed to handle this for numbers where the precision varied, you'd have to either pass them as strings or pass the precision as a separate value for use in your formatting code. HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Mar 4, 9:50 pm, Bob bro...@packagingcorp.com wrote: I'm relativley new to PrototypeJS. I am doing some calculation in a back end program and returning a JSON string to my web page. One of the values is a price. If I return 14.20, it gets converted in evalJSON to 14.2. I want to keep both digits. I can find how to pad the left of a nmber to a certain number of places, but can't seem to find anythig about keeping decimals out to a set number of places. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Decimal places
On Mar 5, 7:50 am, Bob bro...@packagingcorp.com wrote: I'm relativley new to PrototypeJS. I am doing some calculation in a back end program and returning a JSON string to my web page. One of the values is a price. If I return 14.20, it gets converted in evalJSON to 14.2. I want to keep both digits. I can find how to pad the left of a nmber to a certain number of places, but can't seem to find anythig about keeping decimals out to a set number of places. Others have answered your question (pass the value as a string), here's a bit more information on the topic if you are doing in-page calculations and wondering why they don't quite add up: How do I format a Number as a String with exactly 2 decimal places? URL: http://www.jibbering.com/faq/#formatNumber -- Rob --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---