diff --git a/cases/float.py b/cases/float.py
new file mode 100644
index 00000000..a7fc8021
--- /dev/null
+++ b/cases/float.py
@@ -0,0 +1,3 @@
+price_val = 6.12658
+world = "swoole"
+print(f'{price_val:.2f}, hello={world}') # 6.13
diff --git a/conv.php b/conv.php
index 5cc303c9..f730d7bb 100644
--- a/conv.php
+++ b/conv.php
@@ -263,7 +263,7 @@ class Translator
case 'Subscript':
return $this->parseSubscript($value);
case 'FormattedValue':
- return $this->parseValue($value->value);
+ return $this->parseFormattedValue($value);
case 'UnaryOp':
return $this->parseTarget($value);
case 'BoolOp':
@@ -921,6 +921,22 @@ class Translator
$code = 'return ' . $lines[0] . PHP_EOL;
return $code . PHP_EOL . $this->getIndent() . '}';
}
+
+ private function parseFormattedValue($value)
+ {
+ $expr = $this->parseValue($value->value);
+ if ($value->format_spec and $value->format_spec->_type == 'JoinedStr') {
+ if (count($value->format_spec->values) != 1) {
+ debug($value);
+ }
+ $format = $value->format_spec->values[0]->value;
+ if ($format[0] == '.' and $format[-1] == 'f') {
+ return 'round(' . $expr . ', ' . substr($format, 1, strlen($format) - 2) . ')';
+ }
+ } else {
+ return $expr;
+ }
+ }
}
error_reporting(E_ERROR);
diff --git a/web/public/index.php b/web/public/index.php
index 82063abc..a9247cc3 100644
--- a/web/public/index.php
+++ b/web/public/index.php
@@ -20,11 +20,12 @@