Round the numbers

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #32741 quote
    JohnVS
    Participant
    Junior

    hi,

    Could someone please tell me how i get round numbers. I only want 2 numbers after the komma

    code i have now =

    a= mashort
    if mashort<mashort[1] then
    DRAWTEXT(" BEAR ■",barindex+0.5,+0.7,SansSerif,Bold,12)coloured(255,0,0)
    Drawtext("#a#",barindex-Xoffset-1.35,+0.7,SansSerif,Bold,12)coloured(0,0,0)

     

    the #a# gives the numbers, but 2 would be enough like 15.06

    Thanks in advance

    rgds

    John

    Round-numbers-2017-04-20_13-51-33.jpg Round-numbers-2017-04-20_13-51-33.jpg
    #32756 quote
    JC_Bywan
    Moderator
    Master

    Hi,

    To the best of my knowledge, there’s no direct way to specify how many digits after comma, but there’s a way to do it with small extra calculation. The only function available would be round(x) to make a round number (no digits beyond comma)  out of a real number x. So my trick is to multiply x by 10^N, round this, and then divide the rounded value by 10^N, N being the number of digits wanted after comma.

    For example, in your case you would be interested to have N=2 and do: a=round(mashort*100)/100

    Nicolas thanked this post
    #32769 quote
    JohnVS
    Participant
    Junior

    Noobywan,

    Thank you very much !! so simple haha

    Thumbs up to you !

     

    rgds

    John

    #179072 quote
    wtangsiri
    Participant
    Junior

    TimeFrame(1 day)
    MyPivotD1 = (High[1] + Low[1] + Close[1]) / 3
    MyPivotD1Rounded = Round(MyPivotD1, 2)

     

    Tout simplement

    #179081 quote
    robertogozzi
    Moderator
    Legend

    Yes, it's easy now, but back then the second parameter to ROUND () didn't exist.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Round the numbers


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
JohnVS @johnvs Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by robertogozzi
4 years, 11 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 04/20/2017
Status: Active
Attachments: 1 files
Logo Logo
Loading...