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!

Rounding to 2 Significant Figures.

Status
Not open for further replies.

CRCRCR

Technical User
Nov 4, 2007
44
AU
Has anyone managed in Crystal to round to significant figures. (Not decimal places)

I've tried replicating the old excel trick, from

which gives

=ROUND(value,2-(1+INT(LOG10(ABS(value)))))

In excel plugging in the value of 1.44 leads to (displays as) 1.4 which seems correct. However multiplying this by 1000, then leads to 1440, which shows that this formula doesn't really work perfectly.

Translating this into Crystal, with additional problems, (I start with a text field, and Crystal doesn't have LOG10)

IF left({@Results-Paper},1) = "<" Then
(
"<" & round(tonumber(mid({@Results-Paper},2)),2-(1+INT(LOG(ABS(tonumber(mid({@Results-Paper},2)))/LOG(10)))))
)
ELSE totext(round(tonumber(mid({@Results-Paper},1)),2-(1+INT(LOG(ABS(tonumber(mid({@Results-Paper},1)))/LOG(10))))))


In Crystal, plugging in the 1.44, results in 1.4400 (1.4000 would be suitable)

In file/options I have set the Numeric field to 4 decimal places, because I have to display other numeric texts to this precision.

Anyone have any ideas to simply, round a number to 2 significant figures?

Cheers, Kai
 
Right-click on the field you want to adjust. Choose [Format Field], the Number tab and [Customise]. ROunding and decimal places are separate, so you could get it showing 1.4400 without fancy formulas.

If you do want to use formulas, Truncate can get rid of unwanted decimals. Something like
Code:
ToText((Truncate({your.field}, 2), 4)
Experiment a bit and see what Crystal can do - a lot more than Excel.

It helps to give your Crystal version - 8, 8.5, 9, 10, 11 or whatever. Methods sometimes change between versions, and higher versions have extra options. In this case, it probably makes no difference.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Thanks for your reply,

This is actually a text field, so unfortunately, we cannot easily change the sig figs using the method you suggested.

Cheers anyway, Kai
 
In case anyone else gets this issue, I finally figured it out. I just had some brackets in the wrong place.

IF left({@Results-Paper},1) = "<" Then
(
"<" & Round((tonumber(mid({@Results-Paper},2))),(2-(1+INT(LOG(ABS((tonumber(mid({@Results-Paper},2)))))/LOG(10)))))
)


ELSE
(
Totext(
Round((tonumber(mid({@Results-Paper},1))),(2-(1+INT(LOG(ABS((tonumber(mid({@Results-Paper},1)))))/LOG(10)))))
)
)

is the final result.

So if anyone need to round a textual numbers to 2 sig figs, just replace the 'number' where the {@Results-Paper} is.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top