简体   繁体   中英

Another excel formula situation

I want to be able to display a difference in seconds as (+4.15) or sometimes negatively as (-4.15) and include the parentheses and plus/minus sign.

How can I use a formula to display 34.47-30.32 so it comes out knowing whether or not the difference is positive or negative 4.15?

This is solved now except my next issue is small, but any number ending in 0, such as 4.10, will display as 4.1, without the extra 0. Using the formula given in the first comment, I can't format this to show exactly 4.10. Is it possible? not even cell formatting to show two decimal places works

You can achieve this with the regular cell formats option in excel.

Format your cells to show the number in this way. Or if you need something other than the already available options, then use custom formats.

在此处输入图片说明

Something like this should work:

=TEXT(B1-A1,"+##.##;-##.##")

Though as Jon says - editing the cell format is far more appropriate generally to avoid an issue, select custom and use this:

+##.##;-##.##

Your desired results (eg +4.15 and -4.15 ) are not covered by the various available standard number formats but you can easily apply a custom number format aka CNF.

A CNF can have up to four parts; positive numbers, negative numbers, zero and text. The following will display positive numbers as black and a plus sign, negative numbers as red with a minus sign, a single grey dash instead of zero and blue text. The latter should never be actually used but the blue text will quickly show text that should have been interpreted as a number. The true numbers will be 'padded' off the right edge by a single space.

[Black]_(+#,##0.00_);[Red]_(-#,##0.00_);[Color10]_(* "-"_);[Blue]_(@_)

Example:

在此处输入图片说明

More on custom number formats at Create or delete a custom number format

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM