Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

truncate trailing zero after 2 places of decimal point

Status
Not open for further replies.

ngcn

MIS
Apr 29, 2002
33
MY
what kind of subject is that ???? just don't know how to write the subject. Hope that u can understand !! ;)

I have an Unit Price field in a report, where I want it to display 2 places of decimal point by default, but if user enter with 3 places decimal point value, then the field will show it in 3 places decimal point value and so on. This field will only allow user to enter up to 4 decimal point.

eg:
Unit Price Unit Price
(I want) (I get)
---------- ----------
123.00 123
52.50 52.5
52.638 52.638
9.4253 9.4253

I use the following formula I get from this forum, but it truncate the 2 trailing zeroes after the decimal point. This field should show the 2 trailing zeroes if there is no figure after the decimal point.

local numbervar p1;
local numbervar p2;
local stringvar s1;
s1 := totext({PODetails.Rate},"0.000000000000000");
p1 := instr(s1,".");
p2 := instr(s1+"000000000000000","000000000000000");
if (p2 = p1+1) then s1 := left(s1,p1-1)
else s1 := left(s1,p2-1);
s1;

thank u..

best regards,
ngcn
 
I think - (you do the testing on this one, I'm afraid!) - that this should be on the money.

If it gives you any problems, let me know.

local numbervar p1;
local numbervar p2;
local stringvar s1;
s1 := totext({PODetails.Rate},"0.000000000000000");
p1 := instr(s1,".");
p2 := instr(s1+"000000000000000","000000000000000");
if (p2 = p1+1) then s1 := left(s1,p1+2) //.00 dp
else
if (p2 = p1+2)
then s1 := left(s1,p1+2)//.1 dp
else s1 := left(s1,p2-1);
s1;

Naith
 
Naith,

Thank u very much..... It works fine !!!


Best regards,
ngcn
 
Naith,

I encountered problems when clients open this report. The formula works perfectly when I open the report from my pc, but when it is open from clients' pc, the field with this formula is being round up to 2 places of decimal points. e.g. 23.5984 becomes 23.60.

I m sure that it is the same report my clients & I open, I even tried to replace(with the updated) the report more three times.

Have you encountered this probelm before ??? Could you plese help me ???

Thank you.

best regards,
ngcn

 
Are you supplying teh client with a .rpt file, a VB executeable, a crystal .exe or what? Software Training and Support for Macola, Crystal Reports and Goldmine
714-348-0964
dgilsdorf@mchsi.com
 
dgillz,

Yes, I did. I copied the .rpt file to the location where I call this report from my VB system.

I m sure that I did it b'coz what ever changes I made to the report can be displayed at the client side, only the formula mentioned failed to do so.

regards,
ngcn
 
Don't you have to update the VB application and supply a new one of those as well? I am not a VB guru, hopefully one of them can chime in here. Software Training and Support for Macola, Crystal Reports and Goldmine
714-348-0964
dgilsdorf@mchsi.com
 
Can anyone help me out ??? I don't know why is that I can't get my client to view the report with a formula field correctly(only one formula that is not display accordingly) in their pc. All they see is QtyRecv in 2 digits of decimal point. There is no problem for me to view/print from my pc.

The formula is used to truncate trailing zero after 2 digits of decimal point. In other word, QtyRecv field can display many digits of decimal point depending on how many does the client entered.

This is the formula that I used :

WhilePrintingRecords; NumberVar p1; NumberVar p2;
StringVar s1;
s1 := ToText({GoodsReceipt.QtyRecv},"0.000000000000000");
p1 := instr(s1,".");
p2 := instr(s1+"000000000000000","000000000000000");
if (p2 = p1+1) then s1 := left(s1,p1-1)
else s1 := left(s1,p2-1);
s1;

Thank you for any help !

best regards,
ngcn
 
How are you accessing the report from within VB? If you're using the rdc with external reports ie

set rep = app.openreport("c:\gskdjgfj")
then it should work.

If you're using the RDC within VB and can edit the report in VB then you'll need to either change the report in VB or reimport the report.
Andrew Baines
Chase International
 
AndrewBaines,

You misunderstand me or I have mislead you, I think the subject should be "truncate trailing zero".

The report can be displayed perfectly on my pc & clients pc, no matter what modification I done to it. It's only that specific formula that cannot be displayed according to what I want it to be.

That formula is used to display Qty receive according to user input, they can input figure like 0.7256, 25.36, 12, etc. The problem is it round up those figure with more than 2 digits of decimal point, for example : 0.7256 to 0.73. I cannot set the rounding & the decimal point for this field coz it is not fixed, it should displayed whatever user entered. FYI, this is a float field.

Please help me ! The top management require it to be done ASAP !!

best regards,
ngcn

 
This is a format issue. Dump your formula with variables and use this one instead as conditional formatting.

I dont know how to expres this in VB but in crystal, from the design window, click on the field(s) in question and select format. Go to the number tab and select customize. Click on the "X-2" button to the right of the decimal place indicator and enter the following:

if right(totext({NumberField},4),2)="00" then 2 else
if right(totext({NumberField},1),1)="0" then 3 else 4

I realize that does not explain why your program is not working correctly but hopefully this is a solution.
Software Training and Support for Macola, Crystal Reports and Goldmine
714-348-0964
dgilsdorf@mchsi.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top