1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen,json2: improve -nofloat support (#13117)

This commit is contained in:
playX
2022-01-10 13:42:41 +03:00
committed by GitHub
parent 4ce6e663bf
commit c07ce3ff15
4 changed files with 31 additions and 10 deletions

View File

@@ -106,8 +106,10 @@ fn (mut p Parser) decode_value() ?Any {
kind := p.tok.kind
p.next_with_err() ?
if p.convert_type {
if kind == .float {
return Any(tl.f64())
$if !nofloat ? {
if kind == .float {
return Any(tl.f64())
}
}
return Any(tl.i64())
}

View File

@@ -73,18 +73,25 @@ pub fn (f Any) json_str() string {
return f.str()
}
f32 {
str_f32 := f.str()
if str_f32.ends_with('.') {
return '${str_f32}0'
$if !nofloat ? {
str_f32 := f.str()
if str_f32.ends_with('.') {
return '${str_f32}0'
}
return str_f32
}
return str_f32
return '0'
}
f64 {
str_f64 := f.str()
if str_f64.ends_with('.') {
return '${str_f64}0'
$if !nofloat ? {
str_f64 := f.str()
if str_f64.ends_with('.') {
return '${str_f64}0'
}
return str_f64
}
return str_f64
return '0'
}
map[string]Any {
return f.str()