# Thread: Displaying 2 decimal places

1. ## Displaying 2 decimal places

Hi guys,

I am comparing an amount displayed on screen to one which I have calculated within QA Run. I've used the equation below to round to 2 d.p. as suggested in another post;

OriginalValue = 798.50
RoundedValue = (Int((OriginalValue * 100) + 0.5 )) / 100

However, once the rounding has been done any trailing zeroes are discarded. I want all the values to display to 2 decimal places. I've written the following to do this;

POINT_POS = FindChar( RoundedValue, ".", "Match" )

LEN = Length( RoundedValue )

REV_POINT_POS = LEN - POINT_POS

If OriginalValue = Int(OriginalValue) or RoundedValue = (Int(OriginalValue) + 1) then
RoundedValue = Str( RoundedValue )
RoundedValue = RoundedValue + ".00"
ElseIf REV_POINT_POS = 1 then
RoundedValue = Str( RoundedValue )
RoundedValue = RoundedValue + "0"
EndIf

UserCheck("2 d.p.",1,RoundedValue)

Which works correctly. I was wondering however if there was a neater way to do this, or whether QA Run has a built in function to automatically round to a set number of decimal places - I've not run across one.

Thanks,

Geoff [img]images/icons/tongue.gif[/img]

2. ## Re: Displaying 2 decimal places

Geoff,

I've never found a function to round to a set number of decimal places in QARun. If you want to round to 2 decimal places you might consider using currency format.

Regards

3. ## Re: Displaying 2 decimal places

Don't you love QARun dropping leading and trailing 0's [img]images/icons/smile.gif[/img]

I currently do almost the same thing as you rip_geoff, with a slight variation.

1. Look for the decimal point, if not there add .00

2. If decimal exists, then count digits after it, if 2 do nothing, if 1, then add "0"

The currency format is a possibility and then if need be, just drop the leading currently symbol, be it dollars, euros, pounds...If hadn't thought of that one.

4. ## Re: Displaying 2 decimal places

Thanks guys,

Glad to know I wasn't being blind and missing a simple in-built function [img]images/icons/cool.gif[/img]

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.