New topic: Format optional decimal point
<http://forums.realsoftware.com/viewtopic.php?t=43876> Page 1 of 1 [ 3 posts ] Previous topic | Next topic Author Message markwalsh Post subject: Format optional decimal pointPosted: Fri May 04, 2012 11:24 am Joined: Wed May 20, 2009 4:43 pm Posts: 784 I need to format a number with optional decimal places, I'm using the following code: SKU_W = Format(Product.SKU_Width.Round(2), "###,##0.#") But if the fractional value is zero (Number is an integer), it still shows the decimal point. (e.g. 12 is formatted as '12.') Is there a way to make the decimal point optional (include only if there is a fractional value) within the format string, or do I need to determine if the value is an integer first, and apply a different format to integers and fractional values? _________________ RB 2009r4 Windows XP Top mallen Post subject: Re: Format optional decimal pointPosted: Fri May 04, 2012 12:53 pm Joined: Mon Mar 01, 2010 11:59 pm Posts: 14 What about: SKU_W = Format(Product.SKU_Width.Round(2), "###,##0.#") if right(SKU_W, 1) = "." Then SKU_W = Left(SKU_W, Len(SKU_W) - 1) _________________ mallen iMac 3.4 GHz Intel Core i7, OS X 10.7.3; RS 2011r4.3 "Sometimes you're the windshield, Sometimes you're the bug." â Mark Knopfler, The Bug, 1991 Top markwalsh Post subject: Re: Format optional decimal pointPosted: Fri May 04, 2012 1:04 pm Joined: Wed May 20, 2009 4:43 pm Posts: 784 mallen wrote:What about: SKU_W = Format(Product.SKU_Width.Round(2), "###,##0.#") if right(SKU_W, 1) = "." Then SKU_W = Left(SKU_W, Len(SKU_W) - 1) That's what I ended up doing for now, but if there's a more efficient way using the Format string, I would prefer to do so. _________________ RB 2009r4 Windows XP Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 3 posts ]
-- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
