sprintf with a variable for first parameter

2 views
Skip to first unread message

sfsf

unread,
Mar 13, 2008, 10:33:18 AM3/13/08
to Nemerle Forum
public static format_real (r : double, vornull : int, stellen : int,
nachstellen : int) : string
{
mutable fstr : string = "%";
when (vornull > 0) {
fstr = fstr + "0";
}
fstr = fstr + ztostr(stellen) + "." + ztostr(nachstellen) + "lf";
return(Nemerle.IO.sprintf("%lf" , r )); // works OK
return(Nemerle.IO.sprintf(fstr, r )); // works not
}

Nemerle.IO.sprintf("%lf" , r ) // this works
Nemerle.IO.sprintf(fstr , r ) // this works not

Why ???

VladD2

unread,
Mar 13, 2008, 10:46:20 AM3/13/08
to nemer...@googlegroups.com
2008/3/13, sfsf <s...@granit.de>:

> Nemerle.IO.sprintf("%lf" , r ) // this works
> Nemerle.IO.sprintf(fstr , r ) // this works not
>
> Why ???

The sprintf is macro which check format string in compile-time. It
can't check dynamic format since it not exists at compile-time.

sfsf

unread,
Mar 13, 2008, 11:02:58 AM3/13/08
to Nemerle Forum
hallo,
give it any way to make this (format_real) in an other way ???

VladD2

unread,
Mar 13, 2008, 11:06:45 AM3/13/08
to nemer...@googlegroups.com
2008/3/13, sfsf <s...@granit.de>:

> hallo,
> give it any way to make this (format_real) in an other way ???

You can use string.Format(), or write you own method.

Reply all
Reply to author
Forward
0 new messages