Skip to main content
Post Undeleted by Wheat Wizard
Post Deleted by Zombo
deleted 1202 characters in body
Source Link
Zombo
  • 1
  • 10

Rust, 124

fn f(n:f64)->String{
let n2=n.log(1e3);
let n3=n/1e3f64.powi(n2 as i32);
format!("{:.3}",n3)+["","k","M","G"][n2 as usize]
}
fn main(){
println!("{}",f(9012345678e0)=="9.012G");
}

Nim, 139

import math,strformat
proc f(n:float):string=
 let n2=int log10(n)/3
 let n3=n/pow(1e3,float n2)
 return fmt"{n3:.3f}"&["","k","M","G"][n2]
echo f(9012345678e0)=="9.012G"

Dart, 146

import 'dart:math';
String f(double n){
var n2=(log(n)/ln10/3).toInt();
var n3=n/pow(1e3,n2);
return n3.toStringAsFixed(3)+['','k','M','G'][n2];
}
void main(){
var s=fprint(f(9012345678);
print(s=='9=='9.012G');
}

Go, 156

package main
import(
"fmt"
"math"
)
func f(n float64)string{
n2:=int(math.Log10(n))/3
n3:=n/math.Pow10(n2*3)
return fmt.Sprintf("%.3f",n3)+[]string{"","k","M","G"}[n2]
}
func main(){
println(f(9012345678)=="9.012G")
}

D, 156

import std.format,std.math,std.stdio;
string f(real n){
auto n2=cast(int)log10(n)/3;
auto n3=n/pow(1e3,n2);
return format("%.3f",n3)~["","k","M","G"][n2];
}
void main(){
writeln(f(9012345678)=="9.012G");
}

C#, 168

using System;
class P{
static string f(double n){
var n2=(int)Math.Log10(n)/3;
var n3=n/Math.Pow(1e3,n2);
return String.Format("{0:f3}",n3)+new[]{"","k","M","G"}[n2];
}
static void Main(){
Console.WriteLine(f(9012345678)=="9.012G");
}
}

Rust, 124

fn f(n:f64)->String{
let n2=n.log(1e3);
let n3=n/1e3f64.powi(n2 as i32);
format!("{:.3}",n3)+["","k","M","G"][n2 as usize]
}
fn main(){
println!("{}",f(9012345678e0)=="9.012G");
}

Nim, 139

import math,strformat
proc f(n:float):string=
 let n2=int log10(n)/3
 let n3=n/pow(1e3,float n2)
 return fmt"{n3:.3f}"&["","k","M","G"][n2]
echo f(9012345678e0)=="9.012G"

Dart, 146

import 'dart:math';
String f(double n){
var n2=(log(n)/ln10/3).toInt();
var n3=n/pow(1e3,n2);
return n3.toStringAsFixed(3)+['','k','M','G'][n2];
}
void main(){
var s=f(9012345678);
print(s=='9.012G');
}

Go, 156

package main
import(
"fmt"
"math"
)
func f(n float64)string{
n2:=int(math.Log10(n))/3
n3:=n/math.Pow10(n2*3)
return fmt.Sprintf("%.3f",n3)+[]string{"","k","M","G"}[n2]
}
func main(){
println(f(9012345678)=="9.012G")
}

D, 156

import std.format,std.math,std.stdio;
string f(real n){
auto n2=cast(int)log10(n)/3;
auto n3=n/pow(1e3,n2);
return format("%.3f",n3)~["","k","M","G"][n2];
}
void main(){
writeln(f(9012345678)=="9.012G");
}

C#, 168

using System;
class P{
static string f(double n){
var n2=(int)Math.Log10(n)/3;
var n3=n/Math.Pow(1e3,n2);
return String.Format("{0:f3}",n3)+new[]{"","k","M","G"}[n2];
}
static void Main(){
Console.WriteLine(f(9012345678)=="9.012G");
}
}

Dart, 146

import 'dart:math';
String f(double n){
var n2=(log(n)/ln10/3).toInt();
var n3=n/pow(1e3,n2);
return n3.toStringAsFixed(3)+['','k','M','G'][n2];
}
void main(){
print(f(9012345678)=='9.012G');
}
deleted 14 characters in body
Source Link
Zombo
  • 1
  • 10

Ruby, 8884

def f(n)
n2=Math.log10(n).to_i/3
return '%.3f'% (n/1e3**n2)+['',' k''k',' M''M',' G'][n2]'G'][n2]
end
p f(9012345678.0)=='9.012 G'012G'

Python, 9794

import math
def f(n):
 n2=int(math.log10(n)/3)
 return '%.3f'%(n/1e3**n2)+('',' k''k',' M''M',' G''G')[n2]
print(f(9012345678)=='9.012 G'012G')

JavaScript, 104

function f(n){
let n2=Math.trunc(Math.log10(n)/3);
return (n/1e3**n2).toFixed(3)+['','k','M','G'][n2];
}
console.log(f(9012345678)=='9.012G');

PHP, 100105

<?php
function f($n){
$n2=(int)(log10($n)/3);
return sprintf('%.3f',$n/1e3**$n2).['',' k''k',' M''M',' G'][$n2];'G'][$n2];
}
var_dump(f(9012345678)=='9.012 G'012G');

JavaScript, 108

function f(n){
let n2=Math.trunc(Math.log10(n)/3);
return (n/1000**n2).toFixed(3)+['',' k',' M',' G'][n2];
}
console.log(f(9012345678)=='9.012 G');

Rust, 125124

fn f(n:f64)->String{
let n2=n.log(1e3);
let n=nn3=n/1e3f64.powi(n2 as i32);
format!("{:.3}",nn3)+[""," k""k"," M""M"," G"][n2"G"][n2 as usize]
}
fn main(){
println!("{}",f(9012345678e0)=="9.012 G"012G");
}

Nim, 140139

import math,strformat
proc f(n:float):string=
 let n2=int log10(n)/3
 let n=nn3=n/pow(1e3,float n2)
 return fmt"{nn3:.3f}"&[""," k""k"," M""M"," G"][n2]"G"][n2]
echo f(9012345678e0)=="9.012 G"012G"

Dart, 143146

import 'dart:math';
String f(double n){
var n2=(log(n)/ln10/3).toInt();
nvar n3=n/=powpow(10001e3,n2);
return nn3.toStringAsFixed(3)+['',' k''k',' M''M',' G'][n2];'G'][n2];
}
void main(){
print(fvar s=f(9012345678)=='9;
print(s=='9.012 G'012G');
}

Go, 156

package main
import(
"fmt"
"math"
)
func f(n float64)string{
n2:=int(math.Log10(n))/3
n3:=n/math.Pow10(n2*3)
return fmt.Sprintf("%.3f",n3)+[]string{"","k","M","G"}[n2]
}
func main(){
println(f(9012345678)=="9.012G")
}

D, 151156

import std.format,std.math,std.stdio;
string f(real n){
auto n2=cast(int)log10(n)/3;
nauto n3=n/=powpow(1e3,n2);
return format("%.3f",nn3)~[""," k""k"," M""M"," G"][n2];"G"][n2];
}
void main(){
writeln(f(9012345678)=="9.012 G"012G");
}

C#, 153168

using System;
class AP{
static string Ff(double n){
intvar n2=Convert.ToInt32n2=(int)Math.Log10(n))/3;
nvar n3=n/=MathMath.Pow(1e3,n2);
return String.Format("{0:f3}",nn3)+new[]{""," k""k"," M""M"," G""G"}[n2];
}
static void Main(){
Console.WriteLine(Ff(9012345678)=="9.012 G"012G");
}
}

Go, 155

package main
import(
"fmt"
"math"
)
func f(n float64)string{
n2:=int(math.Log10(n))/3
n/=math.Pow10(n2*3)
return fmt.Sprintf("%.3f",n)+[]string{""," k"," M"," G"}[n2]
}
func main(){
println(f(9012345678)=="9.012 G")
}

Ruby, 88

def f(n)
n2=Math.log10(n).to_i/3
return '%.3f'% (n/1e3**n2)+['',' k',' M',' G'][n2]
end
p f(9012345678.0)=='9.012 G'

Python, 97

import math
def f(n):
 n2=int(math.log10(n)/3)
 return '%.3f'%(n/1e3**n2)+('',' k',' M',' G')[n2]
print(f(9012345678)=='9.012 G')

PHP, 100

<?php
function f($n){
$n2=(int)(log10($n)/3);
return sprintf('%.3f',$n/1e3**$n2).['',' k',' M',' G'][$n2];
}
var_dump(f(9012345678)=='9.012 G');

JavaScript, 108

function f(n){
let n2=Math.trunc(Math.log10(n)/3);
return (n/1000**n2).toFixed(3)+['',' k',' M',' G'][n2];
}
console.log(f(9012345678)=='9.012 G');

Rust, 125

fn f(n:f64)->String{
let n2=n.log(1e3);
let n=n/1e3f64.powi(n2 as i32);
format!("{:.3}",n)+[""," k"," M"," G"][n2 as usize]
}
fn main(){
println!("{}",f(9012345678e0)=="9.012 G");
}

Nim, 140

import math,strformat
proc f(n:float):string=
 let n2=int log10(n)/3
 let n=n/pow(1e3,float n2)
 return fmt"{n:.3f}"&[""," k"," M"," G"][n2]
echo f(9012345678e0)=="9.012 G"

Dart, 143

import 'dart:math';
String f(double n){
var n2=(log(n)/ln10/3).toInt();
n/=pow(1000,n2);
return n.toStringAsFixed(3)+['',' k',' M',' G'][n2];
}
void main(){
print(f(9012345678)=='9.012 G');
}

D, 151

import std.format,std.math,std.stdio;
string f(real n){
auto n2=cast(int)log10(n)/3;
n/=pow(1e3,n2);
return format("%.3f",n)~[""," k"," M"," G"][n2];
}
void main(){
writeln(f(9012345678)=="9.012 G");
}

C#, 153

using System;
class A{
static string F(double n){
int n2=Convert.ToInt32(Math.Log10(n))/3;
n/=Math.Pow(1e3,n2);
return String.Format("{0:f3}",n)+new[]{""," k"," M"," G"}[n2];
}
static void Main(){
Console.WriteLine(F(9012345678)=="9.012 G");
}
}

Go, 155

package main
import(
"fmt"
"math"
)
func f(n float64)string{
n2:=int(math.Log10(n))/3
n/=math.Pow10(n2*3)
return fmt.Sprintf("%.3f",n)+[]string{""," k"," M"," G"}[n2]
}
func main(){
println(f(9012345678)=="9.012 G")
}

Ruby, 84

def f(n)
n2=Math.log10(n).to_i/3
return '%.3f'% (n/1e3**n2)+['','k','M','G'][n2]
end
p f(9012345678.0)=='9.012G'

Python, 94

import math
def f(n):
 n2=int(math.log10(n)/3)
 return '%.3f'%(n/1e3**n2)+('','k','M','G')[n2]
print(f(9012345678)=='9.012G')

JavaScript, 104

function f(n){
let n2=Math.trunc(Math.log10(n)/3);
return (n/1e3**n2).toFixed(3)+['','k','M','G'][n2];
}
console.log(f(9012345678)=='9.012G');

PHP, 105

<?php
function f($n){
$n2=(int)(log10($n)/3);
return sprintf('%.3f',$n/1e3**$n2).['','k','M','G'][$n2];
}
var_dump(f(9012345678)=='9.012G');

Rust, 124

fn f(n:f64)->String{
let n2=n.log(1e3);
let n3=n/1e3f64.powi(n2 as i32);
format!("{:.3}",n3)+["","k","M","G"][n2 as usize]
}
fn main(){
println!("{}",f(9012345678e0)=="9.012G");
}

Nim, 139

import math,strformat
proc f(n:float):string=
 let n2=int log10(n)/3
 let n3=n/pow(1e3,float n2)
 return fmt"{n3:.3f}"&["","k","M","G"][n2]
echo f(9012345678e0)=="9.012G"

Dart, 146

import 'dart:math';
String f(double n){
var n2=(log(n)/ln10/3).toInt();
var n3=n/pow(1e3,n2);
return n3.toStringAsFixed(3)+['','k','M','G'][n2];
}
void main(){
var s=f(9012345678);
print(s=='9.012G');
}

Go, 156

package main
import(
"fmt"
"math"
)
func f(n float64)string{
n2:=int(math.Log10(n))/3
n3:=n/math.Pow10(n2*3)
return fmt.Sprintf("%.3f",n3)+[]string{"","k","M","G"}[n2]
}
func main(){
println(f(9012345678)=="9.012G")
}

D, 156

import std.format,std.math,std.stdio;
string f(real n){
auto n2=cast(int)log10(n)/3;
auto n3=n/pow(1e3,n2);
return format("%.3f",n3)~["","k","M","G"][n2];
}
void main(){
writeln(f(9012345678)=="9.012G");
}

C#, 168

using System;
class P{
static string f(double n){
var n2=(int)Math.Log10(n)/3;
var n3=n/Math.Pow(1e3,n2);
return String.Format("{0:f3}",n3)+new[]{"","k","M","G"}[n2];
}
static void Main(){
Console.WriteLine(f(9012345678)=="9.012G");
}
}
deleted 3 characters in body
Source Link
Zombo
  • 1
  • 10
def f(n)
n2=Math.log10(n).to_i/3
return '%.3f'% (n/1000**n21e3**n2)+['',' k',' M',' G'][n2]
end
putsp f(9012345678.0)=='9.012 G'
def f(n)
n2=Math.log10(n).to_i/3
return '%.3f'% (n/1000**n2)+['',' k',' M',' G'][n2]
end
puts f(9012345678.0)=='9.012 G'
def f(n)
n2=Math.log10(n).to_i/3
return '%.3f'% (n/1e3**n2)+['',' k',' M',' G'][n2]
end
p f(9012345678.0)=='9.012 G'
added 2 characters in body
Source Link
Zombo
  • 1
  • 10
Loading
Source Link
Zombo
  • 1
  • 10
Loading