The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Hi,

I have some float fields in a database example the yen 127.60 I need to convert this to be left with a round integer value of 128

Thanks

Andy

I have some float fields in a database example the yen 127.60 I need to convert this to be left with a round integer value of 128

Thanks

Andy

Some more info about rounding in Delphi:

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21302630.html

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_10031374.htm

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_10369657.html

I am calculating a sun for the japanese yen 225.22 - 224.77 , I get the answer 1.04 but I want int converting to 104 as an integer value.

The float value comes from a database field.

The round function gives 1

Thanks

Andy

225.22 - 224.77

and you get 1.04 ????

I do not follow

The rounding functions can be expanded to different styles of rounding... you just need to show us by example what you need to achieve... (try just with numbers (math))

for example I use this modified function for rounding:

function RoundD(x: Extended; d: Integer): Extended;

// RoundD(123.456, 0) = 123.00

// RoundD(123.456, 2) = 123.46

// RoundD(123456, -3) = 123000

var

n: Extended;

begin

n := IntPower(10, d);

x := x * n;

Result := (Int(x) + Int(Frac(x) * 2)) / n;

end;

Regards

But I'm still somewhat confused. In your first example you said:

>I have some float fields in a database example the yen 127.60 I need to convert this to be left with a round integer value of 128

Which would indeed be rounding, unlike

SomeInt:=Trunc(AFloat*100)

So do you expect 12760 or 128 in that example?

I need to have 127.60 which is a Float field then convert this to be left with a round integer value of 128.

So do you expect 12760 or 128 in that example?<== 127.60 to 128

Thanks

Andy

Andy, you really need to clarify what your doing. In one comment you indicate that:

>> 1.04 should read 104

and then

>> 127.60 should read 128

The first can only be achieved by * 100 and then Round'ing, the second is achieved through Round'ing only. These are 2 seperate calculations, so what are you looking for?

Russell

Round(127.60) will result in 128

Round(1.04) will result in 1, not 104

Rounding uses the fractional part of the number to either increment (or not) the whole part of the number, the result is an integer value (whole number, no fractions) that much we can all agree on. The confusion is coming from your statement of "104" from 1.04 . The only way to come up with that is to multiply 1.04 * 100, resulting in 104.00 and then Round that number. If you did the same to 127.60, eg:

127.60 * 100

= 12760.00

Round(12760)

= 12760

The results you are looking for; 104 and 128; cannot be achieved using a single function, as the math you are applying to each is different.

Russell

Here is what I'm trying to do.

I need to get the number of points betweenthe market open and market close for the currency Euro V USD, the market Low is 1.3121 and the market High is 1.3203.

I need to deduct the high from the low which gives 0.00818169 this is the points from high to low, now I need to round this number to an integer value of 82 with no zeros or decimal point.

Hope this is more clear

Many Thanks for your Help

Andy

Is it ok if e.g. 0.000018169 becomes 0?

Do you mean something like this?

function ShiftRound(HighF,LowF:Sing

begin

Result:=Round((HighF-LowF)

end;

procedure TForm1.Button1Click(Sender

var

h,l:Single;

begin

h:=1.3203;

l:=1.3121;

Edit1.Text:=IntToStr(Shift

end;

function ShiftRound(f1,f2:Single):I

begin

if f1>f2 then

Result:=Round((f1-f2)*1000

else if f1<f2 then

Result:=Round((f2-f1)*1000

else

Result:=0;

end;

Andy,

What you are dealing with here is called "scaling". In your first example, no scaling was applied. In the 104 from 1.04 example, a scaling of 2 was applied (10^2), in this last example, the scaling applied was 4 (10^4). The math is easy, but you will need to specify the scaling factor to be applied to the values (each value had a different scale applied).

function ScaleRound(Value: Double; Scale: Integer): Integer;

var dblScale: Double;

begin

// Set scaling factor

dblScale:=1;

// Build scale value

while (Scale > 0) do

begin

dblScale:=dblScale * 10;

Dec(Scale);

end;

// Apply scaling and round result

result:=Round(Value * dblScale);

end;

Example Usage:

ShowMessage(IntToStr(Scale

ShowMessage(IntToStr(Scale

ShowMessage(IntToStr(Scale

---

Russell

But couldn't the function be simplified to something like:

Result:=Round(Value*Power(

Any drawbacks to this?

This is what I'm trying to achive:

Euro V Dollar Days High = 1.3130 Days Low = 1.3030 I need to remove the decimal point and end up with 100 this is the pips spread for the day.

Euro V Sterling Days High = 0.6780 Days Low = 0.6760 I need to remove the decimal point and the zeros and end up with 20 this is the pips spread for the day.

Sterlin V Yen Days High = 227.73 Days Low = 227.48 I need to remove the decimal point and end up with 25 this is the pips spread for the day.

Thanks

Andy

Nope (on the drawbacks), except I didn't want to drag the Math unit in.

Andy,

Again it comes down to scaling, which we can't determine for you. Your scaling (point spead) is based on the currency being evaluated. The numbers themselves do not determine the scaling factor to apply, its what they represent (currency-wise) that does. YOU need to determine that part.

Russell

Ok I'll go from here and see how I get on, I'll increase the point themn split them.

Thanks for your help.

Andy

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

Something like:

procedure TForm1.FormCreate(Sender: TObject);

begin

Edit1.Text:=FloatToStr(0.0

end;

Function StripChar(AString : String; AChar : Char) : String;

var

P : Integer;

S : String;

begin

S := AString;

P := pos(AChar,S);

While P > 0 do

begin

Delete(S,P,1);

P := pos(AChar,S);

end;

Result := s;

end;

procedure TForm1.Button1Click(Sender

var

s:string;

begin

s:=FloatToStr(round(StrToI

If StrLen(PChar(s))>=3 then

s:=s[1]+s[2]+'.'+s[3];

ShowMessage(FloatToStr(Rou

end;

This seems to be doing the job you described that you needed

Regards