Quantcast
Channel: YouTrackReSharper (RSRP) - Bug and Issue Tracker
Viewing all articles
Browse latest Browse all 106942

RSRP-328950: CA: "Format numeric value" that provides builder for standard/custom format strings

$
0
0
Reporter Drew Noakes (drewnoakes) Drew Noakes (drewnoakes)
Created Aug 5, 2012 2:34:17 PM
Updated Apr 16, 2018 3:26:05 PM
Subsystem Context Actions
Assignee Alisa Afonina (alisa.afonina)
Priority Major
State Open
Type Feature
Fix version Backlog
Affected versions 2018.1, 7.0
Fixed In Version ReSharper Undefined
VsVersion All Versions
Full control of the conversion from numeric values to strings requires memorising some mini-languages:

- Standard Numeric Format Strings
- Custom Numeric Format Strings

Remembering all the details of these languages is tough, but they're actually very useful. ReSharper's in a great position to help out.

double d = 123.4;
Console.WriteLine(d|);

With the caret positioned as shown, R# detects that a conversion from a numeric type to a string is going to take place, and a CA is available that helps the developer build a valid numeric format string for the appropriate numeric type. The builder replaces the need to check online reference material as it lists all options and provides examples of how they format various values.

The builder provides all formatting options, including padding, decimal places, conversion to hex, presentation of negative numbers, scientific representation, percentage representation, etc.

This could also be available in other places that formatting might apply:

int i = 1234;
Console.WriteLine("{0|}", i); // Console.WriteLine("{0:#,##0}", i)
Console.WriteLine(i|); // Console.WriteLine(i.ToString("X4"));
var s = "ID = " + i|; // var s = "ID = " + i.ToString("D6");

Equally, the CA is available on existing numeric formatting operations, and may be used to find out how it's going to format the value in question.

Support for custom format strings (both for positive/negative) would be great too.

Since standard conversions are culture sensitive, a builder may allow for investigation of conversions to strings in different cultures. This can be very useful when designing UI layouts that fail in other cultures because strings are longer/shorter than expected.

Related to issue: http://youtrack.jetbrains.com/issue/RSRP-328948

Viewing all articles
Browse latest Browse all 106942

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>