How to display only two decimals except for whole numbers in rmarkdown - format

I am using rmarkdown to create a document. I want all numbers to have two decimals except for the whole numbers where I don´t want any decimal point. I am using the following commands:
knitr::knit_hooks$set(inline = function(x) {
prettyNum(x, big.mark=",")
})
options(scipen=1, digits=2)
However, when I have a number like 60.9785 it shows only 60. And if I change for digits=3, a number like 1.2644 it´s displayed like 1.264. How can I solve this?

Related

Split Two decimals After Dot in Google Sheets Formula

I've two sets of corrupted numbers where two columns of data got merged.
1.504.99
4.604.97
18.955.00
1.154.85
0.301.82
And Like this:
0.0514.29%
0.1530.00%
0.2583.33%
0.000.00%
1.30185.71%
I want to split the each column two digits after the first dot for example 1.30185.71% as 1.30 | 185.71%
I tried split and regexreplace inside arrayformula as a noob as much as I can but as of now, nothing is working. Is there any way to make this work? Please help. Sheet is attached here
Try
1st
=arrayformula(if(A2:A="",,regexextract(A2:A,"\d+\.\d{2}")))
and 2nd
=arrayformula(if(A2:A="",,regexextract(A2:A,"\d+\.\d{2}(.*)")))
edit
you can add value to tranform in numeric, 1st
=arrayformula(if(A2:A="",,value(regexextract(A2:A,"\d+\.\d{2}"))))
and 2nd
=arrayformula(if(A2:A="",,value(regexextract(A2:A,"\d+\.\d{2}(.*)"))))

Google Sheets - Split Formula

I have a sheet where we paste values copied from a pdf into a column, such as:
2715411.0 28.10.2021 600.00
In Google sheets there are columns with formulas that split these values, one of each is:
=ArrayFormula(INDEX(SPLIT(REGEXREPLACE(C2:C274, "\s", "♥"),"♥"),ROW(C2)-ROW(C2),1))
This formula is returning "2715411" instead of "2715411.0". I've tested the formula if the value was "2715411.1" and it works so I'm assuming it's because the number is being "rounded".
Another thing to take into consideration is that sometimes the number we paste is something like "32434346 28.10.2021 600.00" so having always decimal places can't be the answer.
Can anyone help?
Thank you in advance.
=ArrayFormula(SUBSTITUTE(SPLIT(SUBSTITUTE(C2:C274,".","♦")," "),"♦","."))

In Google Sheets, how do we take a decimal feet value and turn it into properly formatted fractional Feet & Inches?

Been looking all over and nothing comes up as far as a Google Sheets formula.
Let's say we have a value of 3.6875 feet. We can use the number format # ??/??, but it will give us a fractional value in feet (in this case, 3 11/16 feet).
How do we "grab" the 11/16 and multiply it by 12 to get the inches value (8.25), and then the really tricky part, how do we display the whole enchilada as 3'8¹/⁴" (yes, including the superscript)?
A1= 3.6875
B1=INT(A1)&"'-"&TRIM(TEXT(ROUND(MOD(A1,1)*12*16,0)/16,"# ??/??")&"""")
Output: 3'-8 1/4 "
UPDATED:
You can have a table to search the superscript
The idea to get the superscript: with above output (3'-8 1/4"): is to extract the fraction (1/4), search for the equivalent superscript in the table (¹/⁴), then replace it (3'-8 ¹/⁴"):
So basically we will need:
REGEXEXTRACT
VLOOKUP
REGEXREPLACE
SPREADSHEET DEMO: HERE
=arrayformula(
if(len(A2:A),INT(A2:A)&"'-
"&REGEXREPLACE(TRIM(TEXT(ROUND(MOD(A2:A,1)*12*16,0)/16,"#??/??")&""""),
"\d{1}\/\d+",
VLOOKUP(IFNA(
REGEXEXTRACT(TRIM(TEXT(ROUND(MOD(A2:A,1)*12*16,0)/16,"# ??/??")&""""),
"\d{1}\/\d+"),
"0/0"),
TABLE!A:B,2,0)),""))

rounding a number in ruby

I would like to round this figure to the nearest whole number. I am generating an xml based on an excel file, and would like to round the figure.
Here is my code:
xml.POS110 “wert”: “#{row[18]}”
I have tried:
xml.POS110 “wert”: “#{row[18]}”.round(0)
Move the round inside the quotes. Before, you were just trying to round a string. Also the default argument for round is 0 so you don't need to specify it (but you can if you really want to).
“#{row[18].round(0)}"

jFreeCharts large number label display

I am using jfreecharts to vreate a value-time chart.
Data is gathered dynamically from web services and some times there are large numbers in it. The chart is created without any problem but the value axis
labels are of this format: 2E10 etc. I would like to have 20000000000 displayed. I have not find any solution after 2 hours of rsearching. Can anyone suggest something?
This fixed the problem:
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
DecimalFormat newFormat = new DecimalFormat("0.0000");
rangeAxis.setNumberFormatOverride(newFormat);
It also works when you have a dataset with largest value a float with 0 as integer part and at least the first 3 decimal digits to be 0 in which case labels also appear in negative power of 10 by default.

Resources