Print Page | Close Window

Type conversion and extracting part of value

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=10536
Printed Date: 03 May 2024 at 12:45pm


Topic: Type conversion and extracting part of value
Posted By: Gurojee
Subject: Type conversion and extracting part of value
Date Posted: 14 Jul 2010 at 4:28pm
Hi,

I want to extract a part of values from the decimal field. I want to covert the decimal value i.e. "0.00010000" to string and extract the value from left untill it is not whole number. for example, in the above value I want to get out "0.0001" from left and the rest of 0s on the right side on 1 should be omitted on the report. Similarly, if the value in the database field is "0.02000000" then I just want to extract the value "0.02" and rest of 0s should not be displayed on the report. I got the below code which works fine but it does returns NO VALUE if the value in the database field is "1.00000000". I want it to return "1" if the value is 1.00000000.

if tonumber(datafield) = 1.00000000 then '1'
else

local stringvar text:=totext(datafield), 8,"");
local numbervar n:=3;

while text[n] = '0' do

(n:=n+1);
text:= left(text,n);


Any Idea plz?

GJ



Replies:
Posted By: Emir_W
Date Posted: 14 Jul 2010 at 7:29pm
try to help.
 
if int(tonumber(datafield))>0 then totext(int(tonumber(datafield)))
else
   ... yours ...
 
 
hope it work.
 


-------------
Emir W


Posted By: Gurojee
Date Posted: 18 Jul 2010 at 8:36pm
Hi,

I tried below code
 
if int(tonumber(datafield))>0 then totext(int(tonumber(datafield)))
else

....... mine....


But still same output.....Doesn't return any value.


Confused




Posted By: Emir_W
Date Posted: 18 Jul 2010 at 9:58pm
i'm using this formula and it's work for me.
 
note, where {?datastr} is string variable.
 
 
if int(tonumber({?datastr}))>0 then totext(int(tonumber({?datastr})),0)
else
(
  local stringvar text:=totext(tonumber({?datastr}), 8,"");
  local numbervar n:=3;
  while text[n] = '0' do
    (n:=n+1);
  text:= left(text,n);
)
 
i put value:
--> '.00001200', it gives me '0.00001'
--> '1.00000', it gives me '1'
 
 
hope it help.
 
 


-------------
Emir W


Posted By: Gurojee
Date Posted: 20 Jul 2010 at 3:24pm
Thanks Emir.... it worked perfectly Big%20smile



Print Page | Close Window