Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Tony Vignone
  Where is Tony Vignone?
 St Augustine
 Florida - United States
 Tony Vignone
 To: Rajesh Samadia
  Where is Rajesh Samadia?
 Jaipur
 India
 Rajesh Samadia
 Tags
Subject: RE: Convert Number to Character
Thread ID: 345574 Message ID: 345599 # Views: 61 # Ratings: 0
Version: Visual FoxPro 6 Category: General VFP Topics
Date: Thursday, May 24, 2012 7:25:58 PM         
   


> Hello Everyone
>
> I want to convert 15.398 to character format
>
> - The number of decimal places is not Known it could be 3,4,5 or more
>
> - STR(15.398,12,5) Result is 15.39800 is not acceptable I need the result as 15.398
>
> - STR(15.390,12,5) Result is 15.39000 is not acceptable I need the result as 15.390
>
> How can this be carried out?
>
> Regards

Try this function to get the character format of a number. Minimum decimal places defaults to 3

clear
?cNumber(15.39800)
?cNumber(15.39000)
?cNumber(234.56789108000)
?cNumber(234.567890000)
?cNumber(234.56)
?cNumber(234,2)
FUNCTION cNumber(nNumber,minDecPlaces)
	minDecPlaces = evl(minDecPlaces,3)
	local i,cnumber
	cnumber = str(nNumber,20,10)
	i =len(m.cnumber)
	do while m.i > at(".",m.cnumber)+minDecPlaces and substr(m.cnumber,m.i,1) = "0"
		i = m.i-1
	enddo	
	cnumber = left(m.cnumber,m.i)
RETURN ltrim(m.cnumber)


Tony

ENTIRE THREAD

Convert Number to Character Posted by Rajesh Samadia @ 5/24/2012 3:48:30 PM
RE: Convert Number to Character Posted by Martin Krivka @ 5/24/2012 4:04:17 PM
RE: Convert Number to Character Posted by Rajesh Samadia @ 5/24/2012 4:26:39 PM
RE: Convert Number to Character Posted by Martin Krivka @ 5/24/2012 6:00:31 PM
RE: Convert Number to Character Posted by Ilya Rabyy @ 5/24/2012 4:10:54 PM
RE: Convert Number to Character Posted by Rajesh Samadia @ 5/24/2012 4:29:43 PM
RE: Convert Number to Character Posted by Anders Altberg @ 5/24/2012 5:36:28 PM
RE: Convert Number to Character Posted by Ilya Rabyy @ 5/24/2012 7:03:27 PM
RE: Convert Number to Character Posted by Anders Altberg @ 5/26/2012 6:13:34 PM
RE: Convert Number to Character Posted by David Mustakim @ 5/26/2012 6:43:25 PM
RE: Convert Number to Character Posted by Anders Altberg @ 5/26/2012 7:02:46 PM
RE: Convert Number to Character Posted by David Mustakim @ 5/26/2012 8:08:50 PM
RE: Convert Number to Character Posted by Tony Vignone @ 5/26/2012 8:21:21 PM
RE: Convert Number to Character Posted by David Mustakim @ 5/26/2012 8:39:01 PM
RE: Convert Number to Character Posted by tushar @ 5/24/2012 4:45:04 PM
RE: Convert Number to Character Posted by Rajesh Samadia @ 5/26/2012 9:21:13 AM
RE: Convert Number to Character Posted by tushar @ 5/26/2012 1:02:15 PM
RE: Convert Number to Character Posted by Tony Vignone @ 5/24/2012 7:25:58 PM
RE: Convert Number to Character Posted by Rajesh Samadia @ 5/26/2012 9:25:37 AM
RE: Convert Number to Character Posted by Anders Altberg @ 5/26/2012 12:59:30 PM
RE: Convert Number to Character Posted by Tony Vignone @ 5/26/2012 2:57:00 PM
RE: Convert Number to Character Posted by Tony Vignone @ 5/26/2012 5:54:21 PM
RE: Convert Number to Character Posted by David Mustakim @ 5/26/2012 3:14:14 PM
RE: Convert Number to Character Posted by Tony Vignone @ 5/26/2012 8:19:16 PM
RE: Convert Number to Character Posted by David Mustakim @ 5/26/2012 8:49:11 PM
RE: Convert Number to Character Posted by Luis Maria Guayan @ 5/28/2012 1:33:17 AM
RE: Convert Number to Character Posted by Tony Vignone @ 5/28/2012 4:42:39 PM
RE: Convert Number to Character Posted by Norberto Gomez Moure @ 5/29/2012 1:07:39 AM
RE: Convert Number to Character Posted by David Mustakim @ 5/29/2012 7:20:47 AM
RE: Convert Number to Character Posted by Tony Vignone @ 5/29/2012 3:06:41 PM
RE: Convert Number to Character Posted by Norberto Gomez Moure @ 5/29/2012 5:05:08 PM