LTspice - limiting the number of decimals

Member
Joined 2005
Paid Member
Alright, can't seem to figure this one out, not helped by the fact my Google-Fu is not what it used to be due to excessive intake of sugary treats (it is Christmas afterall).

I have a schematic drafted where I want to label a number of nodes with their DC voltages in a transient analysis.

I do this by simply left clicking on the nodes in question, et voila, the DC voltage shows up. However, it shows up formatted with 5 decimal places, which is a little too much. I'd like to round that off to one or two decimal places.

If I however right click the node and add the expression 'round(V(a1))' to round off the voltage at node 'a1' it rounds off to no decimal numbers, which in my case means that 1.38798V is rounded to 1V, that's not what I'm after, I'd like to see either 1.4V or 1.39V.

Any of you fine gentlemen know how to accomplish this undoubtedly trivial feat? Thanks and Merry Christmas!
 
AX tech editor
Joined 2002
Paid Member
Alright, can't seem to figure this one out, not helped by the fact my Google-Fu is not what it used to be due to excessive intake of sugary treats (it is Christmas afterall).

I have a schematic drafted where I want to label a number of nodes with their DC voltages in a transient analysis.

I do this by simply left clicking on the nodes in question, et voila, the DC voltage shows up. However, it shows up formatted with 5 decimal places, which is a little too much. I'd like to round that off to one or two decimal places.

If I however right click the node and add the expression 'round(V(a1))' to round off the voltage at node 'a1' it rounds off to no decimal numbers, which in my case means that 1.38798V is rounded to 1V, that's not what I'm after, I'd like to see either 1.4V or 1.39V.

Any of you fine gentlemen know how to accomplish this undoubtedly trivial feat? Thanks and Merry Christmas!

Sander I think it should be round(V(a1),2) . Does that work?

BTW, my latest install of LTspiceXVII crashes every 10 minutes or so. On two different machines, a laptop and a PC, both running W10 Pro. Anybody seen this too, know why?

Jan
 
Member
Joined 2005
Paid Member
Sander I think it should be round(V(a1),2) . Does that work?

No, unfortunately not, syntax error.

BTW, my latest install of LTspiceXVII crashes every 10 minutes or so. On two different machines, a laptop and a PC, both running W10 Pro. Anybody seen this too, know why?

Using W10 Pro (64bit) here too, have not had it crash yet (fingers crossed).
 
AX tech editor
Joined 2002
Paid Member
The x1000k seems to work with current reading but not voltage.

Try .option numdgt = 3

Default, numdgt = 6.
Historically "numdgt" was used to set the number of significant figures used for output data. In LTspice, if "numdgt" is set to be > 6, double precision is used for dependent variable data.

Found it in here: Linear Audio | your tech audio resource ;-)

Jan
 
Ex-Moderator
Joined 2011
The above command controls the precision of the calculation, not the number of decimal places that LTSpice displays AFAIK.

In any case, after further searches, here is the way to limit the decimal places per ltwiki:
Undocumented LTspice - LTwiki-Wiki for LTspice

Code:
round($*1k)/1k ; display no more than 3 digits (typically automatically expressed in engineering format).
round(I(R1)*1k)/1k ; same display format as above, but expression is of the current through R1.
round(V(1,2)*1k)/1k ; same format, but expression is of the voltage difference between nodes 1 & 2.
 
Member
Joined 2005
Paid Member
The above command controls the precision of the calculation, not the number of decimal places that LTSpice displays AFAIK.

Exactly, that was the 1st thing I tried.

In any case, after further searches, here is the way to limit the decimal places per ltwiki:
Undocumented LTspice - LTwiki-Wiki for LTspice

Code:
round($*1k)/1k ; display no more than 3 digits (typically automatically expressed in engineering format).
round(I(R1)*1k)/1k ; same display format as above, but expression is of the current through R1.
round(V(1,2)*1k)/1k ; same format, but expression is of the voltage difference between nodes 1 & 2.

Yeah, that's basically what we discussed in previous replies, it is a bit cumbersome though, as you'll have to manually relabel every node, rather than apply a global rule that applies to all number rounding.
 
It's an old thread, but ...

Maybe this helps, these functions limit the length of a figures to a set length independent of the exponent while at the same time :) rounding the number.

0.000012345 -> 0.0000123 (when 3 significate figures requested)
0.000012366 -> 0.0000124 (when 3 significate figures requested)
1234.500000 -> 1230 (when 3 significate figures requested)
1236.600000 -> 1240 (when 3 significate figures requested)
works also for other numbers.

Frans.

;==============================================================================
; === FdWs Rounding functions by Frans de Wit for Signature Origin (diyAudio.com)
; === Truncate round to a fixec fixed number of figures
;==============================================================================
;V=round(v(inp,inn)/(10**floor(log10(v(inp,inn))-2)))*(10**floor(log10(v(inp,inn))-2)); B-source formula for 3 figures
;V=round(v(inp,inn)/(10**floor(log10(v(inp,inn))-5)))*(10**floor(log10(v(inp,inn))-5)); B-source formula for 6 figures
.func rndx(a,x) {round(a/(10**floor(log10(a)-(x-1))))*(10**floor(log10(a)-(x-1)))}; Function for x figures
.func rnd3(a) {round(a/(10**floor(log10(a)-2)))*(10**floor(log10(a)-2))}; Function for 3 figures
.func rnd6(a) {round(a/(10**floor(log10(a)-5)))*(10**floor(log10(a)-5))}; Function for 6 figures
 
O.k. now I'm doing requests :)
What about this...
 

Attachments

  • Rounding.asc
    2.8 KB · Views: 101
  • Rounding.png
    Rounding.png
    63.8 KB · Views: 352
I can't remember where I found this method of rounding, it seems to work:

round(I(R13)*100k)/100k
or
round(V(n006)*1k)/1k

change the bold parameters to increase or decrease the number of decimal places.

For example 100 will give you 2 decimal places > 15.25v
1K will give you 3 decimal places > 1.731v
100k will give you 2 decimal places > 3.12mA or 7.73mV
10000k will give you 4 decimal places > 3.9668mA

You'll have to experiment with the scaling factor to obtain the required rounding values.
 

Attachments

  • rounding.jpg
    rounding.jpg
    85.9 KB · Views: 283
Last edited:
The function that you show rounds to the number specified to the number of leading figures specified by the number, e.g. 100k in the sample. Any number less than (1/100k)/2 will be shown as zero.

The function that I show rounds to the number of digits specified to the significant first figures, as specified, leading in the number to round.

That is something different. This is especially useful when using the rnd?(<n>[,<d>]) functions that are given. e.g. there is little to remember, so it is easy to use.

p.s. When using the function that you quote, you will need the number of, expected, leading zero's beforehand. This can lead to falsely identifying a number as zero when it is smaller than expected (by the rounding formula).
 
Last edited:
The second sentence, of my previous post, is a bit confusing, at the least it confuses me :)
Probably this is better:

The function that I show rounds to the number of figures specified. These figures are the leading figures in the number to round ignoring any leading zero's (behind the decimal point).
 
Last edited:
AX tech editor
Joined 2002
Paid Member
Frans I still don't get it. Suppose I have a node labelled A, where I placed an .op data label. I want to limit the displayed value to 3 decimals.
When I run the sim, I can edit the expression for that node value, where V(a) is represented by the string operator $.

So I edit the expression to {rnd3(V(a))} but that is not accepted, throwing an error 'undefined symbol'. What is the correct way, can it work in this case?
I did copy your function definitions to the current schematic of course.

Jan