Advertisement
rotrevrep

double to string

May 23rd, 2013
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 0.34 KB | None | 0 0
  1. public static void main(){
  2.     double d = 12.2627;
  3.     stdout.printf("%s\n",double_to_string_p(d,2));
  4. }
  5.  
  6. public string double_to_string_p(double d, int precision){
  7.     string s = d.to_string();
  8.     stdout.printf("%s\n",s);
  9.     string[] a = s.split(".");
  10.     if(a.length < 2) return s;
  11.     a[1] = a[1].substring(0,precision);
  12.     return string.joinv(".",a);
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement