How do you cast a Double to an an Int in Vala?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
jemimah
Posts: 4307
Joined: Wed 26 Aug 2009, 19:56
Location: Tampa, FL
Contact:

How do you cast a Double to an an Int in Vala?

#1 Post by jemimah »

I'm working on Vattery, a battery meter for the systray, which is written in Vala. It seems that the Double class in Vala lacks a to_int() method, so to cast a double to an int I've been using Double.to_string().to_int(). Surely there's a better way? The Vala reference manual is woefully incomplete.

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#2 Post by BarryK »

Perhaps this is a dumb suggestion, but won't a caste do it?

a = (int) b;

...or, doesn't casting extend to this type of conversion?
[url]https://bkhome.org/news/[/url]

User avatar
jemimah
Posts: 4307
Joined: Wed 26 Aug 2009, 19:56
Location: Tampa, FL
Contact:

#3 Post by jemimah »

Yep, that works. Thanks.

User avatar
jemimah
Posts: 4307
Joined: Wed 26 Aug 2009, 19:56
Location: Tampa, FL
Contact:

#4 Post by jemimah »

Maybe you can help me with another Vala problem.

When I compile with Vala I get this error:

Code: Select all

/root/vattery/vattery-retro-jemimah-patches/main.vala:309: undefined reference to `gtk_status_icon_set_tooltip_text'
The correct code for our version of Gtk is 'gtk_status_icon_set_tooltip'. I've been killing the build script halfway though so I can fix the generated C code, and then finishing the build by hand.

Is there a permanent way to fix this?

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#5 Post by BarryK »

jemimah wrote:Maybe you can help me with another Vala problem.
Heh heh, no that was just a lucky stab at it the last time. I wouldn't have a clue how to fix that gtk problem!
[url]https://bkhome.org/news/[/url]

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#6 Post by Lobster »

. . . for those wondering with valour 'bout Vala
http://puppylinux.org/wikka/ValaGenieintro
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

Post Reply