PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, September 18, 2022

[FIXED] How to print F32 with 1 dec place and a fixed width in rust

 September 18, 2022     formatting, printing, rust, width     No comments   

Issue

Trying to replicate the following C printf invocation

printf("%6.1f %6.1f %6.1f\n", x, y, z);

in rust and I can't find it in the docs. I need 6 positions wide with 1 decimal place.

First time I've been stumped finding what I need there.


Solution

Formatting strings are documented in the documentation for std::fmt.

The equivalent of %6.1f would be {:6.1}:

println!("{:6.1} {:6.1} {:6.1}", x, y, z);

Playground



Answered By - harmic
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing