×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Display correct number of decimals at runtime

Display correct number of decimals at runtime

Display correct number of decimals at runtime

(OP)
hi,

I would like to display a number field to the correct number of decimals at runtime.

e.g
1.0000 as 1
0.8750 as 0.875
0.5000 as 0.5
2.5000 as 2.5

how can I do that?

Cheers,
Eric Lye
   

RE: Display correct number of decimals at runtime

Hi Eric,
All you have to do is to right click on the field the numbers appear in and choose "Format field" and choose the
numbers tab and from here you can specify how many caracters appears after the decimal.








Peace
Jason

RE: Display correct number of decimals at runtime

(OP)
Hi Moonmouth,

thanks for your reply, but this is not what I need.

I know that we can format number fields through the format field options. What I need is to be able to set the number field dynamically to the correct number of decimal place for each record retrieved.

e.g.

Rcd no. field value desired display
------- ----------- ---------------
1          1.500       1.5
2          0.875       0.875
3          0.250       0.25
 
Regards,
Eric Lye

RE: Display correct number of decimals at runtime

You will have to format it as a string, as this is not a standard numeric format.
The following would do it for a number in the format of 9999.9999.  It simply checks the last character of the decimal portion of the number, and if it is zero, checks the one prior etc.  If it runs into a non zero character in the decimal portion of the number, it displays the string up to that point.  There may be a simpler solution...
Local StringVar TempStr := ToText({Orders.Order Amount}, "####.0000") ;
If TempStr[-1] <> '0' then
  TempStr
Else If TempStr[-2] <> '0' then
  TempStr[1 to -2]
Else If TempStr[-3] <> '0' then
  TempStr[1 to -3]
Else If TempStr[-4] <> '0' then
  TempStr[1 to -4]
Else
  TempStr[1 to 4]

Malcolm Wynden
Authorized Crystal Engineer
http://www.wynden.net
malcolm@wynden.net

RE: Display correct number of decimals at runtime

(OP)
Thanks Malcolm.

This is very helpful.

RE: Display correct number of decimals at runtime

Hi OnDot

If you want a general formula to achieve the same thing...

local numbervar p1;
local numbervar p2;
local stringvar s1
s1 := totext({numfield},"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


This should work with anything provided it does not have more than 15 decimal places !!

Geoff

(PS. I have checked it !!)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close