Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="ISO-8859-1" Message-ID: <1620256.BhNbSm6C5H@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sat, 17 Nov 2012 15:37:02 +0100 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 7Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 33 NNTP-Posting-Date: 17 Nov 2012 15:37:03 CET NNTP-Posting-Host: 9264c820.newsspool4.arcor-online.net X-Trace: DXC=cW^Ql[kg=6f]BlmkiiU@Bi4IUKK`Nj95_PeH=`f6h7]UAPH2Fd X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:17279 Andrew Poulos wrote: > On 17/11/2012 4:12 AM, skrite wrote: >> Javascript: Hey all, if myString = "11." i would like it to be just >> "11" if it is "11.0" i would also like it to just be "11" however, if >> the string ends with anything else, like "11.3" or "11.34" i would >> like to leave it the way it is. Basically, i want to remove the >> decimal point and trailing 0 of any of my strings that are whole >> numbers. > > How about: > > var s= "11."; > var i = parseInt(s, 10); This will convert "11." to a Number value, stopping at `.'. However, the OP wanted decimals to be preserved. > var f = parseFloat(s); This will convert "11." to a Number value; preserving decimals, if any. > s = (i == f ? i : f) + ""; So there is no point in this with regard to the question. PointedEars -- Prototype.js was written by people who don't know javascript for people who don't know javascript. People who don't know javascript are not the best source of advice on designing systems that use javascript. -- Richard Cornford, cljs,