Skip to content

Commit

Permalink
Set the stream locale to "C" locally
Browse files Browse the repository at this point in the history
So that even if there is a global locale
set by the library user, Jsonnet output
is still the same.
  • Loading branch information
sbarzowski committed Oct 30, 2019
1 parent 771845d commit e8aa025
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ limitations under the License.
#include <memory>
#include <set>
#include <sstream>
#include <locale>
#include <string>

#include "ast.h"
Expand All @@ -34,6 +35,9 @@ limitations under the License.
std::string jsonnet_unparse_number(double v)
{
std::stringstream ss;
// Make sure we output the same thing, even if the user
// of the library changed the global locale
ss.imbue(std::locale::classic());
if (v == floor(v)) {
ss << std::fixed << std::setprecision(0) << v;
} else {
Expand Down

0 comments on commit e8aa025

Please sign in to comment.