comp.lang.ada
 help / color / mirror / Atom feed
* Modify value - type duration
@ 2008-11-05 21:50 Andreas.Schmidl
  2008-11-05 22:47 ` Jeffrey R. Carter
  0 siblings, 1 reply; 7+ messages in thread
From: Andreas.Schmidl @ 2008-11-05 21:50 UTC (permalink / raw)


Hello!

I started programming in Ada for about a month. Because of that my
knowledge isn't really good, but will be better every day ;-)
I have a problem to modify a fixed point value  (type duration).

I want to cut all before the point. Example:
---------------------------------------------------
var1 : duration := 12.345;
var2 : duration;

var2 := cutIt(num => var1);
---------------------------------------------------

var2 is now 0.345. To implement the function "cutIt" I tested an idea.
I converte var1 to an integer:

---------------------------------------------------
function cutIt(var : duration) return duration is

tempvar : integer;

begin
	tempvar := integer(var);
	return (var - duration(tempvar));

end cutIt;
--------------------------------------------------

But this isn't a solution. Converting to integer with integer(...)
round the value.
Example:
12.345 ---> 12
12.854 ---> 13

Is there any other more elegant and functional solution in Ada?

Thanks for your help!

Best regards!

Andreas



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-11-07 11:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-05 21:50 Modify value - type duration Andreas.Schmidl
2008-11-05 22:47 ` Jeffrey R. Carter
2008-11-06  1:03   ` Adam Beneschan
2008-11-06  1:57     ` Jeffrey R. Carter
2008-11-06 21:14       ` Keith Thompson
2008-11-07  1:33       ` Randy Brukardt
2008-11-07 11:10         ` Ludovic Brenta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox