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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Currency-varying decimal places (but always min 2 decimals) 1

Status
Not open for further replies.

rose4567

Programmer
Mar 12, 2007
70
US
I need to format a currency field. I'm hoping someone can help me craft decimal and rounding formulas within a custom numeric style.

I always need at least two decimal places displayed =

Database Value Report Display
35 35.00
35.5 35.50
35.032 35.023
35.3694 35.3694
.0045 .0045


I've looked through a bunch of other posts, but all the code samples I located drop trailing zeros. Standard formatting of the field doesn't work either since that displays trailing zeros like 35.0000.

If anyone has any ideas I'd be greatful.

Thank you!

 
The following might work for you as a formula for the decimal formatting formula area. Both the decimal formatting and the rounding should be set to the maximum number of places also.

numbervar dec := 9; //9
numbervar i;
numbervar j := dec + 1;
numbervar x;

for i := 1 to j do (
if val(right(totext(currentfieldvalue,j,""),i)) = 0 then
x := j - i);
if x > 2 then
x else
2

This would remove zeros, but only down to two places.

-LB
 
Tested and this works great. Thank you so much LB!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top