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:
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user