0 Replies - 1004 Views - Last Post: 13 January 2010 - 05:37 PM

#1 athlon32  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 117
  • View blog
  • Posts: 363
  • Joined: 20-August 08

Vala - Rounding Doubles

Posted 13 January 2010 - 05:37 PM

Description: Just compile :DA function that rounds doubles and returns ints
using GLib;

public class example : GLib.Object {
    public static int main(string[] args) {
	stdout.printf("345.67 rounds off to: %d", Round(345.67));
	return 0;
    }

    public static int Round(double num) {
	(num > 0) ? (num+= 0.5) : (num+= (-0.5));
	return (int)num;
    }
}

Is This A Good Question/Topic? 0
  • +

Page 1 of 1