[Scilab-users] Digit Grouping in msprintf?

classic Classic list List threaded Threaded
5 messages Options
Richard llom Richard llom
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] Digit Grouping in msprintf?

Hey,
is it possible to have this
msprintf('%.f kWh',2725977)
output something like "2.725.977 kWh" or even better "2 725 977 kWh" (with
thin spaces)?

Thanks
richard



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Rafael Guerra Rafael Guerra
Reply | Threaded
Open this post in threaded view
|

Re: Digit Grouping in msprintf?

Hi,

The thousands separator flag for the printf (apostrophe) is non-standard and it does not seem to work in Scilab.
You may need to program this in order to get a nicer printout.

Regards,
Rafael

-----Original Message-----
From: users [mailto:[hidden email]] On Behalf Of Richard llom
Sent: Thursday, November 02, 2017 3:49 PM
To: [hidden email]
Subject: [Scilab-users] Digit Grouping in msprintf?

Hey,
is it possible to have this
msprintf('%.f kWh',2725977)
output something like "2.725.977 kWh" or even better "2 725 977 kWh" (with
thin spaces)?

Thanks
richard



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: Digit Grouping in msprintf?

In reply to this post by Richard llom
Hi Richard,

Are you sure that a relative accuracy of 5e-8 of your result is relevant/actual/significant?!
(.f displays 6 decimal digits after the dot).
If yes, and if
msprintf('%5.2f GWh',2725977/1e6)
does not match your actual data and relative accuracy, AFAIK there is no way with the Scilab C format to group digits.

So, you may post-process the resulting string with some strsplit(s,..) and strcat(s, " ") calls.
Tuning the space's width is mainly/only possible with a LaTeX rendering on graphics.

HTH
Samuel

----- Mail original -----
De: "Richard llom" <[hidden email]>
À: [hidden email]
Envoyé: Jeudi 2 Novembre 2017 15:48:49
Objet: [Scilab-users] Digit Grouping in msprintf?

Hey,
is it possible to have this
msprintf('%.f kWh',2725977)
output something like "2.725.977 kWh" or even better "2 725 977 kWh" (with
thin spaces)?

Thanks
richard



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Richard llom Richard llom
Reply | Threaded
Open this post in threaded view
|

Re: Digit Grouping in msprintf?

Hi Samuel,
I need the number in "kWh", but no digits after the comma.

Postprocessing with strcat(s," ") is a nice idea.
Is there a function to split the number to the power of 10 factors?
Eg. 2725977 becomes
[2 , 725 , 977]

Then it would be really easy. :-)
Thanks
richard



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Rafael Guerra Rafael Guerra
Reply | Threaded
Open this post in threaded view
|

Re: Digit Grouping in msprintf?

Hi,

 

Try this:

 

// START OF CODE
n = 2725977;
p = int(log10(n));
x=[];
for i=p:-3:0;
    x = [x int(n/10^i)];
    n=modulo(n,10^i);
end
// END OF CODE

 

Regards,

Rafael

 

-----Original Message-----
From: users [mailto:[hidden email]] On Behalf Of Richard llom
Sent: Friday, November 17, 2017 5:12 PM
To: [hidden email]
Subject: Re: [Scilab-users] Digit Grouping in msprintf?

 

Hi Samuel,

I need the number in "kWh", but no digits after the comma.

 

Postprocessing with strcat(s," ") is a nice idea.

Is there a function to split the number to the power of 10 factors?

Eg. 2725977 becomes

[2 , 725 , 977]

 

Then it would be really easy. :-)

Thanks

richard

 


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users