Suppress scientific notation in Haxe across targets

122 views
Skip to first unread message

Jason Sturges

unread,
Mar 24, 2017, 10:09:33 PM3/24/17
to Haxe

Is there a way to suppress scientific notation in Haxe?


For example, if I have:


var f:Float = 0.00007075;
var s:String = Std.string(f);


In targets such as html5, this outputs: 0.00007075


However, c++ targets output: 7.075e-05


Is there a way to control whether scientific notation is used for string format?

Franco Ponticelli

unread,
Mar 24, 2017, 10:13:48 PM3/24/17
to haxe...@googlegroups.com

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Hugh

unread,
Mar 27, 2017, 12:52:38 AM3/27/17
to Haxe
You can change the global output mode for floats on cpp using an extern like:

class Test
{
 
@:native("__hxcpp_set_float_format") @:extern
 
static function setFloatFormat(format:String):Void { }
 
 
public static function main()
 
{
    trace
(0.00005);
    trace
(5e20);
    setFloatFormat
("%.12f");
    trace
(0.00005);
    trace
(5e20);
 
}


}

You can only use the standard printf formats, and the change is global, so it may not be what you want.

Hugh

Jason Sturges

unread,
Mar 30, 2017, 2:51:04 PM3/30/17
to haxe...@googlegroups.com
Thanks to you both.

That native extern is very cool; though, I wish I could apply different formats in a single trace statement when outputting multiple variables on a single line.

--
You received this message because you are subscribed to a topic in the Google Groups "Haxe" group.

Jason Sturges

unread,
Mar 30, 2017, 2:58:42 PM3/30/17
to haxe...@googlegroups.com
Actually disregard - the native extern is perfect.  Exactly what I hoped for.  Thanks, again.
Reply all
Reply to author
Forward
0 new messages