## not displaying decimals if 0

## not displaying decimals if 0

(OP)

Hi,

I'm trying to get a report to display numbers without decimals if there are no.

For input I can enter up to 3 decimals, but display is set to format 999.999.999.99 so I think max 2 decimals are displayed.

Most of the time (98%) no decimals are used but they do get displayed on the report.

What I would like is if there is no decimal it should not show them, like:

6,000 >6

6,500> 6,5

6,550>6,55

6,555>6,555

So I think it should count from the last number and max three back if there are any zero's and if it should strip them?

Not sure how to do this in VFP. Maybe somebody can help me?

I'm trying to get a report to display numbers without decimals if there are no.

For input I can enter up to 3 decimals, but display is set to format 999.999.999.99 so I think max 2 decimals are displayed.

Most of the time (98%) no decimals are used but they do get displayed on the report.

What I would like is if there is no decimal it should not show them, like:

6,000 >6

6,500> 6,5

6,550>6,55

6,555>6,555

So I think it should count from the last number and max three back if there are any zero's and if it should strip them?

Not sure how to do this in VFP. Maybe somebody can help me?

## RE: not displaying decimals if 0

What version of Fox are you using? If this is a VFP question, you should post it in the Microsoft: Visual Foxpro forum.

Best Regards,

Scott

ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."

## RE: not displaying decimals if 0

But based on the fact this is a Microsoft based erp, I think you are correct. Is there a way to move this thread to the microsoft visual fox pro forum?

## RE: not displaying decimals if 0

It sounds like this is a commercial product and/or an application that someone built for your company.

My first suggestion is to contact the Developer to get them to make the change.

Unless you have the Source code you can't just make something change how it operates and/or is displayed in an application.

Also, even if the application itself is written in Foxpro, sometimes Reports are generated outside of it - example: Crystal Reports, etc.

Perhaps you need to find out more detail on what you are working with and we might be able to assist you better.

Good Luck,

JRB-Bldr

## RE: not displaying decimals if 0

## RE: not displaying decimals if 0

So to get what you want, you'll want your expression to be something like this (I think the field you're looking at is icNumber; if not, substitute the right name):

## CODE

Tamar

## RE: not displaying decimals if 0

## CODE

Tamar

## RE: not displaying decimals if 0

So I made it like this:

ICASE(ROUND(g_oTemp.LineQtyInv,0)=g_oTemp.LineQtyInv, TRANSFORM(g_oTemp.LineQtyInv, '999,999,999'), MOD(g_oTemp.LineQtyInv,.1)=0, TRANSFORM(g_oTemp.LineQtyInv,'999,999,999.9'), MOD(g_oTemp.LineQtyInv,.01)=0, TRANSFORM(g_oTemp.LineQtyInv,'999,999,999.99'),

But it gives error:missing expression..

## RE: not displaying decimals if 0

Hi Tamar it almost works, it gives:

6,000 > 6

6,500 > 6,5

but then:

6,550 > 6,5,

6,555 > 6,5,5

so first two are ok, but with last 2 are not ok, but I hardly use more than 1 decimals to describe amount of goods, sothis covers 98% of the cases..

edit: and also I wouldlike to add " x" after the number so I made: TRIM(TRANSFORM(g_oTemp.LineQtyInv), 1, '0') + " x"

But that gives wrong results:

6 x

6,5x

6,5, x

6,5,5 x

## RE: not displaying decimals if 0

Do you have something in Format property in the Fomrat tab of that report control? This should just be set as this:

All the formatting already is done by the expression you set in the General tab.

Bye, Olaf.

## RE: not displaying decimals if 0

Format was set to Numeric including a format expression. I changed and removed, now it works!

Thanks you and also Tamar!

## RE: not displaying decimals if 0

## RE: not displaying decimals if 0

You may want to try something like this

## CODE -->

Please do also check your SET DECIMALS - it should be set to the highest number of decimals you want to have displayed

hth

MK

## RE: not displaying decimals if 0

IIF(SET("Point")$TRANSFORM(g_oTemp.LineQtyInv), TRIM(TRIM(TRANSFORM(g_oTemp.LineQtyInv),"0"),SET("Point")), TRANSFORM(g_oTemp.LineQtyInv))+ " x"

## RE: not displaying decimals if 0

That's a bummer.

In my FAQ184-7862: How to calculate with more precision I have a parsing routine for converting any number to a string representation and some meta dataa about it like the number of decimal places (really used places, no 0):

## CODE

This is also removing leading 0 from numbers in the form 0.* or -0.* (that's numbers between -1 and 1, excluding -1 and 1), it's a matter of taste, if you leave this zero in. The most important part in there is determining number of decimal places used by the mere TRASNFORM() conversion via Len(tcNum)-Evl(At(".",tcNum),Len(tcNum)). If the decimal point is not there, you have no decimal places at all, and if it's the rightmost, it would be AT the rightmost postion = length of the string and decimal places still are none. If you have no decimal places, you're not allowed to right trim that.

Stripped down to only generating a string 1:1 this could be simplified in testing, whether TRANSFORM()s result has a decimal point - SET('POINT') - in it or not and only if so, right trim 0 and the decimal point itself, and that's exactly what your expression does.

I would put it in a function like

## CODE

A little trickier would be to add in a decimal point, if it's missing, to then trim it away:

## CODE

Put back into a single expression: TRIM(TRIM(TRANSFORM(g_oTemp.LineQtyInv)+IIF(Set('POINT')$TRANSFORM(g_oTemp.LineQtyInv),'',Set('POINT')),'0'),Set('POINT'))

Bye, Olaf.

## RE: not displaying decimals if 0

## CODE

Anyway, I have already been there - had bugs with numbers like that - and still didn't recognize the error case of Tamars too simple approach, too. Besides my class doesn't take SET('POINT') into account.

Bye, Olaf.