diff --git a/clipboard.cpp b/clipboard.cpp index a93b47d2..392fe7c2 100644 --- a/clipboard.cpp +++ b/clipboard.cpp @@ -235,9 +235,12 @@ void GraphicsWindow::MenuClipboard(int id) { } bool TextWindow::EditControlDoneForPaste(char *s) { + Expr *e; switch(edit.meaning) { case EDIT_PASTE_TIMES_REPEATED: { - int v = atoi(s); + e = Expr::From(s, true); + if(!e) break; + int v = (int)e->Eval(); if(v > 0) { shown.paste.times = v; } else { @@ -246,11 +249,14 @@ bool TextWindow::EditControlDoneForPaste(char *s) { break; } case EDIT_PASTE_ANGLE: - shown.paste.theta = WRAP_SYMMETRIC(atof(s)*PI/180, 2*PI); + e = Expr::From(s, true); + if(!e) break; + shown.paste.theta = WRAP_SYMMETRIC((e->Eval())*PI/180, 2*PI); break; case EDIT_PASTE_SCALE: { - double v = atof(s); + e = Expr::From(s, true); + double v = e->Eval(); if(fabs(v) > 1e-6) { shown.paste.scale = v; } else { diff --git a/mouse.cpp b/mouse.cpp index fa879b6f..f3e9df4c 100644 --- a/mouse.cpp +++ b/mouse.cpp @@ -1134,9 +1134,26 @@ void GraphicsWindow::MouseLeftDoubleClick(double mx, double my) { sprintf(s, "%.3f", c->valA); break; - default: - strcpy(s, SS.MmToString(fabs(c->valA))); + default: { + double v = fabs(c->valA); + char *def = SS.MmToString(v); + double eps = 1e-12; + if(fabs(SS.StringToMm(def) - v) < eps) { + // Show value with default number of digits after decimal, + // which is at least enough to represent it exactly. + strcpy(s, def); + } else { + // Show value with as many digits after decimal as + // required to represent it exactly, up to 10. + v /= SS.MmPerUnit(); + int i; + for(i = 0; i <= 10; i++) { + sprintf(s, "%.*f", i, v); + if(fabs(atof(s) - v) < eps) break; + } + } break; + } } ShowGraphicsEditControl((int)p2.x, (int)p2.y-4, s); }