New topic: 

Format problem

<http://forums.realsoftware.com/viewtopic.php?t=30652>

       Page 1 of 1
   [ 4 posts ]                 Previous topic | Next topic         Author  
Message       basicbasic           Post subject: Format problemPosted: Sun Oct 
25, 2009 12:04 pm                        
Joined: Sun Oct 25, 2009 11:56 am
Posts: 2              When I use Format (a, "#.#") and a=125; the result I get 
is "125."  with the decimal point at the end by itself. I need one decimal 
point precision. Any help is appreciated.

Thanks   
                            Top                Steve Garman           Post 
subject: Re: Format problemPosted: Sun Oct 25, 2009 12:08 pm                    
           
Joined: Fri Sep 30, 2005 3:53 pm
Posts: 3065
Location: England              Have you tried Format (a, "0.0")     
_________________
Steve Garman
Using REALbasic 2008r2 Professional on Windows Vista Ultimate
and REALbasic 2009r4 Professional on Linux Ubuntu 9.04 Desktop
Occasional blog  
                            Top               basicbasic           Post 
subject: Re: Format problemPosted: Sun Oct 25, 2009 12:11 pm                    
    
Joined: Sun Oct 25, 2009 11:56 am
Posts: 2              Steve Garman wrote:Have you tried Format (a, "0.0")

Maybe I should clarify

if a=125 I want string to be "125"
if a =125.5 I want string to be "125.5"
if a=125.52 I want string to be "125.5"

Thanks   
                            Top                Phil M           Post subject: 
Re: Format problemPosted: Sun Oct 25, 2009 12:20 pm                        
Joined: Fri Sep 30, 2005 12:18 pm
Posts: 212              No automatic mask for that (although I wish there was).

Code:If ( num <> Round( num )) Then Return Format( num, "-0.0########" ) Else 
Return Format( num, "-0" )

# is place holder and only shows if there is numeric value to put there (only 
affects non-whole number values)... 0 will always show.  - will show negative 
if there, but will not show if number is positive.  Unless you specifically 
want to ignore negative values, you should always use the - in a Format mask.

Since you want 5.52 to = 5.5, you just use the mask "-0.0" for the case with a 
decimal.   
                            Top           Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 4 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]

Reply via email to